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
13 changes: 5 additions & 8 deletions contains-duplicate/doh6077.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# https://leetcode.com/problems/contains-duplicate/description/

# set에 저장하면서 중복 여부 확인하기
class Solution:
def containsDuplicate(self, nums: list[int]) -> bool:
hashset = set()
for i in nums:
if i in hashset:
return True
hashset.add(i)
return False
def containsDuplicate(self, nums: List[int]) -> bool:
# Create a set to store unique numbers from nums
nums_set = set(nums)
return len(nums_set) != len(nums)
30 changes: 23 additions & 7 deletions two-sum/doh6077.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
# 6기
# class Solution:
# def twoSum(self, nums: list[int], target: int) -> list[int]:
# prevMap = {} # val : index
# for i, n in enumerate(nums):
# diff = target - n
# if diff in prevMap:
# return [prevMap[diff], i]
# prevMap[n] = i

# 7기
# https://leetcode.com/problems/two-sum/description/
class Solution:
def twoSum(self, nums: list[int], target: int) -> list[int]:
prevMap = {} # val : index
for i, n in enumerate(nums):
diff = target - n
if diff in prevMap:
return [prevMap[diff], i]
prevMap[n] = i
def twoSum(self, nums: List[int], target: int) -> List[int]:
# use Hash map to save num and index
nums_hm = {}

for i, num in enumerate(nums):
find_val = target - num

if find_val in nums_hm:
return [nums_hm[find_val], i]

nums_hm[num] = i