2-Line C# Code without recursive -- 68ms


  • -1
    L
    public int HammingWeight(uint n) {
        for(int i = 0, j = 0; i < 33; j += (int)(n & 1), n >>= 1, i++) if(i == 32) return j;
        return 0;
    }

Log in to reply
 

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