二进制中1的个数

class Solution {  
public:  
     int  NumberOf1(int n) {  
         int count = 0;  
         while(n)  
         {  
            ++count;  
             n = (n-1)&n;  
         }  
         return count;  
     }  
};  

 

posted on 2017-03-01 01:23  123_123  阅读(61)  评论(0编辑  收藏  举报