Why does my C++ code not work?


  • 0
    Y

    class Solution {
    public:
    int hammingWeight(uint32_t n) {

        int cnt = 0;
        for(int i = 31;i > 0 ; i--){
            cnt += n / (2^(i-1));
            n = n % (2^(i-1));
        }
        return cnt;
    }
    

    };

    Runtime error :(
    I think there is no problem. can't figure out


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.