You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/0100-0199/0190.Reverse Bits/README_EN.md
+32-28
Original file line number
Diff line number
Diff line change
@@ -44,30 +44,36 @@
44
44
45
45
## Solutions
46
46
47
-
### Solution 1
47
+
### Solution 1: Bit Manipulation
48
+
49
+
We can extract each bit of `n` from the least significant bit to the most significant bit, and then place it in the corresponding position of `ans`.
50
+
51
+
For example, for the $i$-th bit, we can use `(n & 1) << (31 - i)` to extract the $i$-th bit of `n` and place it on the $31 - i$-th bit of `ans`, then right shift `n` by one bit.
52
+
53
+
The time complexity is $O(\log n)$, and the space complexity is $O(1)$.
0 commit comments