Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

191. Number of 1 Bits leetcode solution in c++

#include<iostream>
using namespace std;

class Solution {
public:
	int hammingWeight(uint32_t n) {
		if (n == 0)
			return 0;
		else
			return (n & 1) + hammingWeight(n >> 1);
	}
};

int main()
{
	unsigned int n;
	cin >> n;
	Solution ss;
	cout << ss.hammingWeight(n);
	return 0;
}
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #Number #Bits #leetcode #solution
ADD COMMENT
Topic
Name
1+9 =