-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoSumProblem.py
More file actions
36 lines (23 loc) · 788 Bytes
/
TwoSumProblem.py
File metadata and controls
36 lines (23 loc) · 788 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
27
28
29
30
31
32
33
34
35
36
from unittest import result
maList =[3, 5, 8, 2, 11, 7]
target = 14
class Solution(object):
def __init__(self) -> None:
pass
def twoSum(self, nums, target)-> None:
list_simple = []
indice = []
for i , num in enumerate(nums):
complement = target - num
list_simple.append(complement)
indice.append(i)
return self.additionNum(list_simple,indice,target)
def additionNum(self ,list_simple,indice,target):
n = len(list_simple)
for i in range(n - 1) :
for j in range(i+1 , n) :
if list_simple[i] + list_simple[j] == target :
return [indice[i],indice[j]]
solution =Solution()
result = solution.twoSum(maList, target)
print(result)