Skip to content

Commit e32dd52

Browse files
committed
Added Java solution
1 parent 28be855 commit e32dd52

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Diff for: solution/0190.Reverse Bits/Solution.java

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class Solution {
2+
// you need treat n as an unsigned value
3+
public int reverseBits(int n) {
4+
int res = 0;
5+
for (int i = 0; i < 31; i++, n>>=1, res<<=1) {
6+
res |= (n&1);
7+
}
8+
res |= (n&1);
9+
return res;
10+
}
11+
}

0 commit comments

Comments
 (0)