C# bit manipulation solution


  • 0
    K
    public class Solution {
        public int HammingWeight(uint n) {
            uint count = 0;
            while (n!=0) {
               count += (n&1) ;
               n = n>>1;
            }
            return (int)count;
        }
    }
    

Log in to reply
 

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