Problem :

https://leetcode.com/problems/contains-duplicate/


My Solution :

class Solution:
def containsDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
return len(set(nums)) != len(nums)


Comment :

위 풀이는 그냥 장난이고... 굳이 알고리즘을 생각해서 반복문으로 푼다면 set을 활용하면 된다.


My Solution2 :

class Solution:
def containsDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
already = set()
for n in nums:
if n in already:
return True
already.add(n)
return False