forked from DaleStudy/leetcode-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrivkode.py
More file actions
38 lines (31 loc) · 891 Bytes
/
rivkode.py
File metadata and controls
38 lines (31 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Solution(object):
# 시간복잡도 nlog(n) sort
# 공간복잡도 n 정렬시
def missingNumber_1(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
sort_nums = sorted(nums)
v = 0
for i in sort_nums:
if v != i:
return v
else:
v += 1
return v
# hash를 사용
# 모든 숫자를 dict에 입력
# for문을 돌면서 해당 hash가 dict에 존재하는지 체크
# 시간복잡도 n - for문
# 공간복잡도 n - dict 생성
def missingNumber(self, nums):
hash_keys = dict()
for i in range(len(nums) + 1):
hash_keys[i] = 0
for i in nums:
hash_keys[i] = 1
for i in range(len(nums) + 1):
if hash_keys[i] != 1:
return i
return 0