Skip to content

Commit be7b1c8

Browse files
committed
Reverse Bits
1 parent c202261 commit be7b1c8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

reverse-bits/TonyKim9401.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class Solution {
2+
public int reverseBits(int n) {
3+
// time complexity O(1)
4+
// space complexity O(1)
5+
int output = 0;
6+
7+
for (int i = 0; i < Integer.SIZE; i++) {
8+
output <<= 1;
9+
output += n & 1;
10+
n >>= 1;
11+
}
12+
return output;
13+
}
14+
}

0 commit comments

Comments
 (0)