One Line Simple Java Solution


  • 0
    R

    I used the included function Integer.bitCount(int n) to count the number of 1's.

    public class Solution {
        public int hammingWeight(int n) {
            return Integer.bitCount(n);
        }
    }
    

Log in to reply
 

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