public class Solution {
/**
* @param num: an integer
* @return: an integer, the number of ones in num
*/
public int countOnes(int num) {
int count = 0;
while (num != 0) {
num = num & (num - 1);
count++;
}
return count;
}
};
LintCode365 二进制中有多少个1
最新推荐文章于 2019-06-14 18:23:57 发布