Answers for "191. Number of 1 Bits leetcode solution in c++"

C++
0

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;
}
Posted by: Guest on March-02-2022

Code answers related to "191. Number of 1 Bits leetcode solution in c++"

Browse Popular Code Answers by Language