File tree 1 file changed +35
-0
lines changed
src/onlinePlatform/leetcode/leetcoding_challenge/2023/nov2023/week5
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < algorithm>
2
+ #include < cstdint>
3
+ #include < vector>
4
+ #include < queue>
5
+ #include < set>
6
+ #include < limits>
7
+ #include < map>
8
+ #include < unordered_set>
9
+ #include < unordered_map>
10
+ #include < iterator>
11
+ #include < sstream>
12
+ #include < iostream> // includes cin to read from stdin and cout to write to stdout
13
+ using namespace std ; // since cin and cout are both in namespace std, this saves some text
14
+
15
+ class Solution {
16
+ public:
17
+ int hammingWeight (uint32_t n) {
18
+ int count = 0 ;
19
+ while (n != 0 ) {
20
+ if (n % 2 != 0 ) {
21
+ count += 1 ;
22
+ }
23
+ n >>= 1 ;
24
+ }
25
+ return count;
26
+ }
27
+ };
28
+
29
+ int main () {
30
+ Solution soln;
31
+
32
+ cout << soln.hammingWeight (00000000000000000000000000001011 ) << endl;
33
+
34
+ return 0 ;
35
+ }
You can’t perform that action at this time.
0 commit comments