We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f310a52 commit 1e37b25Copy full SHA for 1e37b25
two-sum/hj4645.py
@@ -0,0 +1,12 @@
1
+class Solution:
2
+ # 2개의 수를 합해 target이 되는 경우를 찾는 문제
3
+ # 순서가 보장되는 python dictionary를 사용해서,
4
+ # 요소 x에 대해서 target-x 가 딕셔너리 내에 있는지를 찾는다.
5
+ def twoSum(self, nums: List[int], target: int) -> List[int]:
6
+ dict = {}
7
+ for i, num in enumerate(nums):
8
+ remain = target - num
9
+ if remain in dict:
10
+ return [dict[remain], i]
11
+ dict[num] = i
12
+
0 commit comments