【leetcode】位1的个数

 

int hammingWeight(uint32_t n) {
    int count=0;
    while(n)
    {
        if(n & 1) count++;
        n >>= 1;
    }
    return count;
}

 

posted @ 2020-09-15 12:31  温暖了寂寞  阅读(113)  评论(0编辑  收藏  举报