diff --git a/solution/0190.Reverse Bits/Solution.java b/solution/0190.Reverse Bits/Solution.java new file mode 100644 index 0000000000000..bcb8afa1cb8ae --- /dev/null +++ b/solution/0190.Reverse Bits/Solution.java @@ -0,0 +1,11 @@ +public class Solution { + // you need treat n as an unsigned value + public int reverseBits(int n) { + int res = 0; + for (int i = 0; i < 31; i++, n>>=1, res<<=1) { + res |= (n&1); + } + res |= (n&1); + return res; + } +} \ No newline at end of file