We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ecb4679 commit f54ec27Copy full SHA for f54ec27
1 file changed
โreverse-bits/jamiebase.pyโ
@@ -0,0 +1,29 @@
1
+"""
2
+# Approach
3
+1) ์ ์๋ฅผ ์ด์ง ๋ฌธ์์ด๋ก ๋ณํํ ๋ค,
4
+32๋นํธ๋ก ๋ง์ถ๊ณ ๋ค์ง์ด์ ๋ค์ ์ ์๋ก ๋ณํํ๋ค.
5
+
6
+2) n์์ ๋นํธ๋ฅผ ํ๋์ฉ ๊บผ๋ด์ res์ ์ญ์์ผ๋ก ๋ถ์ธ๋ค
7
8
+# Complexity
9
+- Time complexity: O(1)
10
+- Space complexity: O(1)
11
12
13
14
+# 1
15
+class Solution:
16
+ def reverseBits(self, n: int) -> int:
17
+ b_num = format(n, "b")
18
+ b_reversed = b_num.zfill(32)[::-1]
19
+ return int(b_reversed, 2)
20
21
22
+# 2
23
24
25
+ res = 0
26
+ for _ in range(32):
27
+ res = (res << 1) | (n & 1)
28
+ n >>= 1
29
+ return res
0 commit comments