forked from DaleStudy/leetcode-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththispath98.py
More file actions
23 lines (21 loc) ยท 860 Bytes
/
thispath98.py
File metadata and controls
23 lines (21 loc) ยท 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution:
def missingNumber(self, nums: List[int]) -> int:
"""
Intuition:
์ฃผ์ด์ง ๋ฆฌ์คํธ์ ๊ฐ์๋ฅผ ์ป์ด ๋ฒ์๋ฅผ ๊ตฌํ๋ค.
์ดํ ์ธํธ๋ฅผ ์ด์ฉํด์ ๋ฒ์ ๋ด์ ์ ์๊ฐ
์ธํธ ์์ ์์ผ๋ฉด ๊ทธ ์๋ฅผ ๋ฆฌํดํ๋ค.
Time Complexity:
O(N):
์ธํธ(ํด์)๋ ์ ๊ทผํ๋ ๋ฐ์ ์์์ ์๊ฐ์ด ๊ฑธ๋ฆฌ๋ฏ๋ก
์ต๋ N + 1๋ฒ์ ์ ๊ทผ์ ํ๋ฏ๋ก
O(N)์ ์๊ฐ๋ณต์ก๋๊ฐ ์์๋๋ค.
Space Complexity:
O(N):
๋ฆฌ์คํธ๋ฅผ ํด์๋ก ๋ณํํ์ฌ ์ ์ฅํ๊ณ ์์ผ๋ฏ๋ก
O(N)์ ๊ณต๊ฐ๋ณต์ก๋๊ฐ ์์๋๋ค.
"""
num_set = set(nums)
for i in range(len(nums) + 1):
if i not in num_set:
return i