Skip to content
Merged
Changes from 2 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
11 changes: 11 additions & 0 deletions contains-duplicate/hj4645.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution:
# 리스트 안에 동일한 숫자가 2개 이상 존재하면 true를 반환해야 하는 문제
# Set으로 변환 시 중복이 제거되므로 List와 Set의 크기를 비교해 답을 구할 수 있음
def containsDuplicate(self, nums: List[int]) -> bool:
return len(nums) != len(set(nums))
Copy link
Contributor

Choose a reason for hiding this comment

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

저도 이런 로직으로 풀이해서 바로 이해가 되었습니다.


# Time Complexity
# - set(nums) → O(n)
# - len(nums), len(set(nums)) → O(1)
# - Total: O(n) (n = number of list elements)