Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions 0217.Contains-Duplicate/memo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 217. Contains Duplicate

## step1
setを使って書いた

## step2

## 他の人のコード

https://github.com/huyfififi/coding-challenges/pull/24

https://github.com/ryosuketc/leetcode_grind75/pull/24

https://github.com/syoshida20/leetcode/pull/32

参考にして解法を追加

`len(nums) != len(set(nums))`、ソート後に隣接要素を比較
8 changes: 8 additions & 0 deletions 0217.Contains-Duplicate/step1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
seen = set()
for n in nums:
if n in seen:
return True
seen.add(n)
return False
12 changes: 12 additions & 0 deletions 0217.Contains-Duplicate/step2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
return len(nums) != len(set(nums))


class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
nums.sort()
for i in range(len(nums) - 1):
if nums[i] == nums[i + 1]:
return True
return False