【leetcode】Number of 1 Bits (easy)

做太多遍了,秒杀。

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

 

posted @ 2015-03-17 16:59  匡子语  阅读(171)  评论(0编辑  收藏  举报