Skip to content

Commit 3bd8372

Browse files
Vedant-SMohamad655
authored andcommitted
Added Leetcode Reverse Bits solution
1 parent c4ed8f8 commit 3bd8372

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

leetcode/cpp/Array/190.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
uint32_t reverseBits(uint32_t n) {
4+
uint32_t res = 0;
5+
uint32_t mask = 1;
6+
for (int i=0;i<32;i++){
7+
if (n&mask) res = res + 1;
8+
if (i!=31) res <<= 1;
9+
mask <<= 1;
10+
}
11+
return res;
12+
}
13+
};

0 commit comments

Comments
 (0)