Skip to content

Commit bd00e38

Browse files
Added solution
1 parent db35ff3 commit bd00e38

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

1.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Runtime: 36 ms, faster than 99.74% of Python3 online submissions for Two Sum.
2+
# Difficulty: Easy
3+
4+
class Solution:
5+
def twoSum(self, nums, target):
6+
"""
7+
:type nums: List[int]
8+
:type target: int
9+
:rtype: List[int]
10+
"""
11+
stored_values = dict()
12+
for index in range(len(nums)):
13+
diff = target - nums[index]
14+
if diff in stored_values:
15+
return [stored_values[diff], index]
16+
stored_values[nums[index]] = index

0 commit comments

Comments
 (0)