Skip to content

Commit 42121ad

Browse files
committed
190
1 parent ca294d1 commit 42121ad

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

190_reverse_bits.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "test.h"
2+
3+
class Solution {
4+
public:
5+
uint32_t reverseBits(uint32_t n) {
6+
uint32_t ret = 0;
7+
uint32_t c = 1;
8+
uint32_t m = c << 31;
9+
for (uint32_t i = 0; i < 32; ++i)
10+
{
11+
if ( (n & c) > 0)
12+
ret |= m;
13+
14+
m >>= 1;
15+
c <<= 1;
16+
}
17+
return ret;
18+
}
19+
};
20+
21+
int main()
22+
{
23+
Solution s;
24+
cout << 4294967293 << " -> " << s.reverseBits(4294967293) << endl;
25+
}

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ targets = \
1616
15_3_sum.exec\
1717
16_3sum_closest.exec\
1818
17_letter_ombinations_of_a_phone_number.exec\
19+
190_reverse_bits.exec\
1920
502_ipo.exec\
2021

2122

0 commit comments

Comments
 (0)