- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoSum.py
More file actions
Latest commit
20 lines (17 loc) · 570 Bytes
/
Copy pathTwoSum.py
File metadata and controls
20 lines (17 loc) · 570 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
chicken= [5, 6, 7, 10, 14, 19]
test= [3, 3, 4, 5, 6, 6, 7, 7]
target=16
testtarget=14
deftwosumv2(nums, target):
fromcollectionsimportdefaultdict
difference=defaultdict(list)
foriinrange(0,len(nums)):
b=target-nums[i]
difference[b].append(i)
forkeyindifference.keys():
ifkey*2==target:
returndifference[key]
elifkeyinnumsand (target-key) innums:
return [nums.index(target-key), nums.index(key)]
print(twosumv2(chicken, target))
print(twosumv2(test, testtarget))