Skip to content

Commit 58c724a

Browse files
committed
Two Sum
1 parent 31ce346 commit 58c724a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Google/Problem#560.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Given a list of numbers and a number k, return whether any two numbers from the list add up to k.
3+
For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17.
4+
Bonus: Can you do this in one pass?
5+
"""
6+
def twoSum(arr,target):
7+
n = set()
8+
for i in arr:
9+
temp = target - i
10+
if temp in n:
11+
return True
12+
n.add(i)
13+
return False

0 commit comments

Comments
 (0)