Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions contains-duplicate/jiunshinn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 시간 복잡도 : o(n)
# 공간 복잡도 o(n)
Comment on lines +1 to +2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

시간 복잡도에는 :를 쓰시고, 공간 복잡도에는 쓰시지 않는 이유가 궁금하네요?



class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
hashmap = {}

for i, n in enumerate(nums):
if n in hashmap:
return True
hashmap[n] = i
return False


# -------------------------------------------------------------------------------------------------------- #

# 시간 복잡도 : o(n)
# 공간 복잡도 o(n)


class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
seen = set()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

집합을 사용하는 이 풀이가 위에 사전을 쓰는 풀이보다 더 깔끔한 것 같습니다!


for n in nums:
if n in seen:
return True
seen.add(n)
return False