标签:quit == bitset set public mingw class min 运算
1 //移位,通过和1进行与操作 2 class Solution { 3 public: 4 int hammingWeight(uint32_t n) { 5 int res=0; 6 while(n)//while n==0,quit while 7 { 8 res+=n&1; 9 n>>=1; 10 } 11 return res; 12 } 13 }; 14 //也可以通过bitset库来计算,好好研究一下bitset库的运用 15 bitset<32> res(n); 16 int countt = res.count() 17 return countt;
标签:quit == bitset set public mingw class min 运算
原文地址:https://www.cnblogs.com/pacino12134/p/11112594.html