Could you please tell me where is my mistake in my solution


  • 0
    W
    public class Solution {
        // you need to treat n as an unsigned value
        public int hammingWeight(int n) {
            int num = 0;
            while(n > 0){
                if(n%2 == 1){
                    num++;
                }
                n >>>= 1;
            }
            return num;
        }
    }

Log in to reply
 

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