Easy C# Solution


  • 0
    S
    public class Solution {
        public int HammingWeight(uint n) {
            string s = Convert.ToString(n, 2);
            int numOnes = 0;
            for (int i = 0; i < s.Length; i++) {
                if (s[i] == '1') {
                    numOnes++;
                }
            }
            return numOnes;
        }
    }

Log in to reply
 

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