[LeetCode][Python3] 217. Contains Duplicate
2018. 11. 4. 21:18 |
프로그래밍/LeetCode
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
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 344. Reverse String (0) | 2018.11.05 |
---|---|
[LeetCode][Python3] 268. Missing Number (0) | 2018.11.04 |
[LeetCode][Python3] 242. Valid Anagram (0) | 2018.11.04 |
[LeetCode][Python3] 237. Delete Node in a Linked List (0) | 2018.11.04 |
[LeetCode][Python3] 204. Count Primes (0) | 2018.11.04 |
[LeetCode][Python3] 202. Happy Number (0) | 2018.11.04 |
[LeetCode][Python3] 191. Number of 1 Bits (0) | 2018.11.04 |
[LeetCode][Python3] 190. Reverse Bits (0) | 2018.11.04 |
최근에 달린 댓글 최근에 달린 댓글