Skip to content

Commit 82fa65d

Browse files
week 8: Reverse Bits - python
1 parent 1f7fba9 commit 82fa65d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

reverse-bits/prograsshopper.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def reverseBits(self, n: int) -> int:
3+
stack_n = []
4+
while len(stack_n) < 32:
5+
stack_n.append((n % 2))
6+
n //= 2
7+
8+
result = 0
9+
scale = 1
10+
11+
while stack_n:
12+
result += stack_n.pop() * scale
13+
scale *= 2
14+
15+
return result

0 commit comments

Comments
 (0)