Skip to content

Commit a0f9f14

Browse files
committed
add week 4 missing number
1 parent 186320c commit a0f9f14

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

missing-number/rivkode.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
class Solution(object):
2+
# 시간복잡도 nlog(n) sort
3+
# 공간복잡도 n 정렬시
4+
def missingNumber_1(self, nums):
5+
"""
6+
:type nums: List[int]
7+
:rtype: int
8+
"""
9+
sort_nums = sorted(nums)
10+
11+
v = 0
12+
for i in sort_nums:
13+
if v != i:
14+
return v
15+
else:
16+
v += 1
17+
18+
return v
19+
20+
# hash를 사용
21+
# 모든 숫자를 dict에 입력
22+
# for문을 돌면서 해당 hash가 dict에 존재하는지 체크
23+
# 시간복잡도 n - for문
24+
# 공간복잡도 n - dict 생성
25+
def missingNumber(self, nums):
26+
hash_keys = dict()
27+
for i in range(len(nums) + 1):
28+
hash_keys[i] = 0
29+
for i in nums:
30+
hash_keys[i] = 1
31+
32+
for i in range(len(nums) + 1):
33+
if hash_keys[i] != 1:
34+
return i
35+
36+
return 0
37+
38+

0 commit comments

Comments
 (0)