-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoSum.py
More file actions
21 lines (19 loc) · 741 Bytes
/
TwoSum.py
File metadata and controls
21 lines (19 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
address_index = []
for i in nums:
if target - i not in nums:
continue
else:
if i == target - i:
address_sameindex = [j for j in range(len(nums)) if nums[j] == i]
if len(address_sameindex) < 2:
continue
else:
address_index = address_sameindex
break
else:
address_index.append(nums.index(i))
address_index.append(nums.index(target - i))
break
return address_index