Skip to content

Commit 23666b2

Browse files
committed
container duplicates solution
1 parent 472e827 commit 23666b2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

contains-duplicate/mrlee7.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
"""
6+
Ideation:
7+
각 원소가 발견되면 hash map 에 해당하는 item 기반으로 flag를 세운다.
8+
해당 인덱스에서 flag가 이미 켜져있다면, 앞에서 탐색된 원소이므로 True를 반환한다.
9+
마지막까지 다 돌았는데 중복된 케이스가 없다면 False를 반환한다.
10+
Time complexity: O(n)
11+
Space complexity: O(n)
12+
"""
13+
14+
def containsDuplicate(self, nums: List[int]) -> bool:
15+
seen = {}
16+
for num in nums:
17+
if num in seen:
18+
return True
19+
seen[num] = 1
20+
return False

0 commit comments

Comments
 (0)