leetcode-剑指15-OK

language: C

address

// 除就完了
int hammingWeight(uint32_t n) {
    uint32_t a =2;
    uint32_t yu;
    int ans = 0;
    for(int i = 0;i < 32; i++){
        yu = n%a;
        if(yu ==1)
            ans++;
        n = n/a;
    }
    return ans;
}
posted @ 2021-01-25 09:22  RougeBW  阅读(33)  评论(0编辑  收藏  举报