标签:question http scribe turn title activity span color 链接
关键点:
记住这几个方法。^ ^
1 public class Solution { 2 public int NumberOf1(int n) { 3 //每次消掉二进制上最低位的1 4 int count =0 ; 5 while(n != 0){ 6 n &=n-1; 7 count++; 8 } 9 return count; 10 //判断二进制每个位置上是不是1 11 /* 12 int count = 0; 13 int flag = 1; 14 while(flag != 0){ 15 if((n&flag)== flag){ 16 count++; 17 } 18 flag<<=1; 19 } 20 return count; 21 */ 22 } 23 }
标签:question http scribe turn title activity span color 链接
原文地址:https://www.cnblogs.com/MoonBeautiful/p/13047198.html