diff --git a/easy/array/217.py b/easy/array/217.py new file mode 100644 index 0000000..d8c94e0 --- /dev/null +++ b/easy/array/217.py @@ -0,0 +1,20 @@ +# Contains Duplicate + +class Solution: + def containsDuplicate(self, nums: list[int]) -> bool: + num_set = set() + for num in nums: + if num in num_set: + return True + num_set.add(num) + else: + return False + +""" +걸린 시간: 7분 + +시간 복잡도: 최악의 경우 모든 요소를 보는데(O(n)), 그때마다 set에 요소의 중복 유무를 확인한다.(O(1)) +따라서 전체 시간복잡도는 O(n)이다. + +해설: 중복 체크를 위해 set을 떠올렸고, 모든 것이 다르다는 것을 구분하려면 전체를 확인해야하기 때문에 전체 요소를 다 확인하였다. +""" \ No newline at end of file