Skip to content

Commit 7d9ca73

Browse files
Merge pull request PawanJaiswal08#54 from jupyterNauticals/master
leetcode number of 1 bits problem
2 parents 95d6d10 + d12ddd0 commit 7d9ca73

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

number_of_1_bits.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
class Solution
2+
{
3+
public:
4+
int hammingWeight(uint32_t n)
5+
{
6+
uint32_t temp = n;
7+
unsigned int count = 0;
8+
while (n)
9+
{
10+
count += (n & 1);
11+
n >>= 1;
12+
}
13+
return count;
14+
}
15+
};
16+
17+
// author:Chinmay Lohani
18+
// date:9-3-2022
19+
// problemName:A. Deletions of Two Adjacent Letters
20+
// problemLink:https://codeforces.com/contest/1650/problem/A
21+
// memoryLimit: 256
22+
// timeLimit:2000
23+
24+
#include <bits/stdc++.h>
25+
26+
using namespace std;
27+
28+
#define mod 998244353
29+
#define lli long long int
30+
#define ll long long
31+
#define li long int
32+
#define FastIO \
33+
ios::sync_with_stdio(0); \
34+
cin.tie(0)
35+
36+
uint32_t solve();
37+
int main()
38+
{
39+
FastIO;
40+
ll tc;
41+
cin >> tc;
42+
while (tc--)
43+
{
44+
cout << solve();
45+
}
46+
return 0;
47+
}
48+
uint32_t solve()
49+
{
50+
uint32_t n;
51+
cin >> n;
52+
uint32_t temp = n;
53+
unsigned int count = 0;
54+
while (n)
55+
{
56+
count += (n & 1);
57+
n >>= 1;
58+
}
59+
return count;
60+
}

0 commit comments

Comments
 (0)