Skip to content
Merged
Changes from 1 commit
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 two-sum/hj4645.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution:
# 2개의 수를 합해 target이 되는 경우를 찾는 문제
# 순서가 보장되는 python dictionary를 사용해서,
# 요소 x에 대해서 target-x 가 딕셔너리 내에 있는지를 찾는다.
def twoSum(self, nums: List[int], target: int) -> List[int]:
dict = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

dict는 파이썬 내장 타입이라 변수명으로 사용하면 좋지 않습니다. 참고 부탁드립니다

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

Loading