Skip to content

Commit 4b57613

Browse files
committed
feat: Add Missing Number solutions
1 parent 5b77982 commit 4b57613

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

โ€Žmissing-number/thispath98.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution:
2+
def missingNumber(self, nums: List[int]) -> int:
3+
"""
4+
Intuition:
5+
์ฃผ์–ด์ง„ ๋ฆฌ์ŠคํŠธ์˜ ๊ฐœ์ˆ˜๋ฅผ ์–ป์–ด ๋ฒ”์œ„๋ฅผ ๊ตฌํ•œ๋‹ค.
6+
์ดํ›„ ์„ธํŠธ๋ฅผ ์ด์šฉํ•ด์„œ ๋ฒ”์œ„ ๋‚ด์˜ ์ •์ˆ˜๊ฐ€
7+
์„ธํŠธ ์•ˆ์— ์—†์œผ๋ฉด ๊ทธ ์ˆ˜๋ฅผ ๋ฆฌํ„ดํ•œ๋‹ค.
8+
9+
Time Complexity:
10+
O(N):
11+
์„ธํŠธ(ํ•ด์‹œ)๋Š” ์ ‘๊ทผํ•˜๋Š” ๋ฐ์— ์ƒ์ˆ˜์˜ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฌ๋ฏ€๋กœ
12+
์ตœ๋Œ€ N + 1๋ฒˆ์˜ ์ ‘๊ทผ์„ ํ•˜๋ฏ€๋กœ
13+
O(N)์˜ ์‹œ๊ฐ„๋ณต์žก๋„๊ฐ€ ์†Œ์š”๋œ๋‹ค.
14+
15+
Space Complexity:
16+
O(N):
17+
๋ฆฌ์ŠคํŠธ๋ฅผ ํ•ด์‹œ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์ €์žฅํ•˜๊ณ  ์žˆ์œผ๋ฏ€๋กœ
18+
O(N)์˜ ๊ณต๊ฐ„๋ณต์žก๋„๊ฐ€ ์†Œ์š”๋œ๋‹ค.
19+
"""
20+
num_set = set(nums)
21+
for i in range(len(nums) + 1):
22+
if i not in num_set:
23+
return i

0 commit comments

Comments
ย (0)