LeetCode50. Pow(x, n)错误,每次都是 299 / 300 test cases passed....

class Solution {  
public:  
    int hammingWeight(uint32_t n) {  
        int count = 0;  
        uint32_t ss = n;  //加上uint32_t 限制,防止越界
        while(ss!=0){  
            if(ss%2){  
                count++;  
            }  
            ss /= 2;  
        }  
        return count;  
    }  
};  

你可能感兴趣的:(LeetCode50. Pow(x, n)错误,每次都是 299 / 300 test cases passed....)