Skip to content

Commit c384610

Browse files
committed
two sum solution
1 parent 0fc7ec8 commit c384610

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

two-sum/changhyumm.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def twoSum(self, nums: List[int], target: int) -> List[int]:
3+
# for i in range(len(nums)):
4+
# for j in range(i+1, len(nums)):
5+
# if nums[i] + nums[j] == target:
6+
# return [i, j]
7+
dic = dict()
8+
for idx, num in enumerate(nums):
9+
if target - num in dic:
10+
return [idx, dic[target-num]]
11+
else:
12+
dic[num] = idx
13+

0 commit comments

Comments
 (0)