We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ca294d1 commit 42121adCopy full SHA for 42121ad
190_reverse_bits.cpp
@@ -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
@@ -16,6 +16,7 @@ targets = \
15_3_sum.exec\
16_3sum_closest.exec\
17_letter_ombinations_of_a_phone_number.exec\
+ 190_reverse_bits.exec\
502_ipo.exec\
0 commit comments