Search
 
SCRIPT & CODE EXAMPLE
 

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;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: cpp practice questions 
Cpp :: Extended Euclid Algorithm Recursive Solution 
Cpp :: Browse Folder Dialog, Search Folder and All Sub Folders using C/C++ 
Cpp :: find the mminimum of the vector and its position in c++ 
Cpp :: find maximum contiguous Sub arrays 
Cpp :: fasdf 
Cpp :: labs c++ 
Cpp :: algorithm map values 
Cpp :: different way to print string in c++ 
Cpp :: draw point sfml 
Cpp :: 3 conditions for a while loop c++ 
Cpp :: python Difference Array | Range update query in O(1) 
Cpp :: How to write string in lpcstr in c++ 
Cpp :: beecrowd problem 1004 solution 
Cpp :: 16630147 
Cpp :: Problems in your to-do list codechef solution in c++ 
Cpp :: arrays to function c++ 
Cpp :: sort 3 numbers using swap cpp 
Cpp :: boundary traversal of binary tree 
Cpp :: qt widget list set selected 
Cpp :: typeid to string c++ 
Cpp :: inversed priority queue 
Cpp :: write c++ code using glbegin and gland() function 
Cpp :: iterator c++ 
Cpp :: function prototype c++ 
Cpp :: constructor overloading in c++ 
Cpp :: binary add using strings 
Cpp :: how to shorten code using using c++ in class with typename 
C :: c check if file exists 
C :: octave square each element matrix 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =