Skip to content

Commit 7c00eae

Browse files
committed
issue #11 190-Done
1 parent 17664d4 commit 7c00eae

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package leetcodeEasyLevel;
2+
3+
public class _0190ReverseBits {
4+
// you need treat n as an unsigned value
5+
public int reverseBits(int n) {
6+
int ret=0;
7+
// because there are 32 bits in total
8+
for (int i = 0; i <32;i++){
9+
ret = ret<<1;
10+
// If the bit is 1 we OR it with 1, ie add 1
11+
if((n & 1) > 0){
12+
ret = ret | 1;
13+
}
14+
n=n>>>1;
15+
}
16+
return ret;
17+
}
18+
}

0 commit comments

Comments
 (0)