Skip to content

Commit e565dfc

Browse files
committed
Add basic template for the second solution: Reverse bit
1 parent 2baf660 commit e565dfc

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

โ€Žreverse-bits/KwonNayeon.pyโ€Ž

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
"""
22
Constraints:
3-
- The input must be a binary string of length 32
4-
3+
- The input must be a binary string of length 32
4+
5+
<Solution 1>
6+
57
Time Complexity: O(1)
6-
- ํ•ญ์ƒ ๊ณ ์ •๋œ 32๋น„ํŠธ ๋ฌธ์ž์—ด์— ๋Œ€ํ•ด ์—ฐ์‚ฐํ•˜๋ฏ€๋กœ ์ƒ์ˆ˜ ์‹œ๊ฐ„
8+
- ํ•ญ์ƒ ๊ณ ์ •๋œ 32๋น„ํŠธ ๋ฌธ์ž์—ด์— ๋Œ€ํ•ด ์—ฐ์‚ฐํ•˜๋ฏ€๋กœ ์ƒ์ˆ˜ ์‹œ๊ฐ„
79
810
Space Complexity: O(1)
9-
- 32๋น„ํŠธ ๊ณ ์ • ํฌ๊ธฐ์˜ ๋ฌธ์ž์—ด ์—ฐ์‚ฐ๋งŒ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ ์ƒ์ˆ˜ ๊ณต๊ฐ„
11+
- 32๋น„ํŠธ ๊ณ ์ • ํฌ๊ธฐ์˜ ๋ฌธ์ž์—ด ์—ฐ์‚ฐ๋งŒ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ ์ƒ์ˆ˜ ๊ณต๊ฐ„
1012
1113
ํ’€์ด ๋ฐฉ๋ฒ•:
12-
1. format(n, '032b')๋ฅผ ์‚ฌ์šฉํ•ด ์ž…๋ ฅ๋ฐ›์€ ์ •์ˆ˜๋ฅผ 32๋น„ํŠธ ์ด์ง„์ˆ˜ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•จ
13-
2. ๋ฌธ์ž์—ด ์Šฌ๋ผ์ด์‹ฑ [::-1]์œผ๋กœ ๋น„ํŠธ๋ฅผ ๋’ค์ง‘์Œ
14-
3. int(reversed_binary, 2)๋กœ ๋’ค์ง‘์€ ์ด์ง„์ˆ˜ ๋ฌธ์ž์—ด์„ ๋‹ค์‹œ ์ •์ˆ˜๋กœ ๋ณ€ํ™˜ํ•จ
14+
1. format(n, '032b')๋ฅผ ์‚ฌ์šฉํ•ด ์ž…๋ ฅ๋ฐ›์€ ์ •์ˆ˜๋ฅผ 32๋น„ํŠธ ์ด์ง„์ˆ˜ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•จ
15+
2. ๋ฌธ์ž์—ด ์Šฌ๋ผ์ด์‹ฑ [::-1]์œผ๋กœ ๋น„ํŠธ๋ฅผ ๋’ค์ง‘์Œ
16+
3. int(reversed_binary, 2)๋กœ ๋’ค์ง‘์€ ์ด์ง„์ˆ˜ ๋ฌธ์ž์—ด์„ ๋‹ค์‹œ ์ •์ˆ˜๋กœ ๋ณ€ํ™˜ํ•จ
1517
"""
1618

1719
class Solution:
@@ -22,3 +24,12 @@ def reverseBits(self, n: int) -> int:
2224
reversed_binary = binary[::-1]
2325

2426
return int(reversed_binary, 2)
27+
"""
28+
<Solution 2>
29+
30+
Time Complexity:
31+
32+
Space Complexity:
33+
34+
ํ’€์ด ๋ฐฉ๋ฒ•:
35+
"""

0 commit comments

Comments
ย (0)