- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwoSum.py
More file actions
Latest commit
26 lines (24 loc) · 590 Bytes
/
Copy pathtwoSum.py
File metadata and controls
26 lines (24 loc) · 590 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
fromcollectionsimportOrderedDict
# l =[2, 7, 11, 15]
# d = {e: i for i,e in enumerate(l)}
# print(d)
deftwoSum(nums,target):
ans= []
d= {}
f=False
foriinrange(0, len(nums)):
t=target-nums[i]
iftind.values():
fork,vind.items():
ifv==tandk!=i:
ans.append(k)
ans.append(i)
f=True
break;
iff:
break
else:
d[i] =nums[i]
returnans
l= [3,2,4]
print(twoSum(l, 6))