-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.py
36 lines (24 loc) · 736 Bytes
/
1.py
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
27
28
29
30
31
32
33
34
35
36
class Solution:
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
result = []
for i in range(len(nums)):
a = target-nums[i]
if a in nums:
y=nums.index(target-nums[i])
if i==y :
continue
else :
result.append(i)
result.append(y)
break
return result
if __name__=='__main__':
solution = Solution()
nums = [2,7,11,15]
target = 9
print(solution.twoSum(nums,target))