Skip to content
Merged
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
12 changes: 12 additions & 0 deletions contains-duplicate/chordpli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import List

class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
dic = {}

for num in nums:
if dic.get(num):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if dic.get(num) 은 num=0일 경우 문제 생길 수 있으므로 더 안전하게 하려면 if num in dic: 사용 추천합니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

감사합니다! 수정하겠습니다!

return True
dic[num] = 1

return False
11 changes: 11 additions & 0 deletions two-sum/chordpli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from typing import List

class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
map = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map은 Python 내장 함수 이름(map())과 겹치므로 다른 변수명 사용 권장합니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

감사합니다! 이후엔 고려해서 변수명을 명명하겠습니다~!

for i, num in enumerate(nums):
complement = target - num
if complement in map:
return [map[complement], i]

map[num] = i