Skip to content

Commit 574c4c3

Browse files
committed
Added two sum
1 parent fcef8f5 commit 574c4c3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

two_sum/solution.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
# @return a tuple, (index1, index2)
3+
def twoSum(self, num, target):
4+
d = {}
5+
for i, e in enumerate(num):
6+
if e in d:
7+
return d[e] + 1, i + 1
8+
d[target - e] = i

0 commit comments

Comments
 (0)