https://leetcode.com/problems/power-of-two/
Given an integer, write a function to determine if it is a power of two.
数字 2^n 是大于0的,而且等于1左移n位得到的数字,所以2^n与2^n-1 相与运算得到0.
bool isPowerOfTwo(int n) {if(n < 0)…
简介2013 年起,为了评测现有的环境声音检测方法,电子与电气工程师学会音频和声学信号处理协会(Institute of Electrical and Electronics Engineers Audio and Acoustic Signal Process, IEEE AASP )开始举办声学场景和事件的检测与分类挑战赛(Detection…
https://leetcode.com/problems/number-of-1-bits/
Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight).
For example, the 32-bit integer ’11’ has binary representation 0000000000000…
https://leetcode.com/problems/counting-bits/
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.
Example: For num 5 you should …
https://leetcode.com/problems/add-binary/
Given two binary strings, return their sum (also a binary string).
For example, a “11” b “1” Return “100”.
计算过程类似Verilog的全加器。
char* addBinary(char* a, char* b) {int i;int l1, l2, l3, temp;…
https://leetcode.com/problems/power-of-three/
Given an integer, write a function to determine if it is a power of three.
Follow up: Could you do it without using any loop / recursion?
3的次方数没有显著的特点,最直接的方法就是不停地除以3&…