Number of 1 Bits

class Solution {
public:
    int hammingWeight(uint32_t n) {
        int result=0;
        
        while(n){
            n=n&(n-1);
            result++;
        }
        
        return result;
    }
};

 

posted @ 2015-04-30 21:48  ~每天进步一点点~  阅读(99)  评论(0编辑  收藏  举报