Skip to content

Commit 0dab597

Browse files
committed
Solve: contains duplicate
1 parent 53ce7c7 commit 0dab597

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

contains-duplicate/hj4645.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
# 리스트 안에 동일한 숫자가 2개 이상 존재하면 true를 반환해야 하는 문제
3+
# Set으로 변환 시 중복이 제거되므로 List와 Set의 크기를 비교해 답을 구할 수 있음
4+
def containsDuplicate(self, nums: List[int]) -> bool:
5+
return len(nums) != len(set(nums))
6+
7+
# Time Complexity
8+
# - set(nums) → O(n)
9+
# - len(nums), len(set(nums)) → O(1)
10+
# - Total: O(n) (n = number of list elements)

0 commit comments

Comments
 (0)