Skip to content

Commit 9725e30

Browse files
authored
Create Two sum
1 parent 79e6e76 commit 9725e30

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Two sum

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
1.Two sum
2+
Given nums = [2, 7, 11, 15], target = 9,
3+
4+
Because nums[0] + nums[1] = 2 + 7 = 9,
5+
return [0, 1].
6+
7+
Python:
8+
class solution(object)
9+
def twoSum(self,nums,target):
10+
self.nums = nums
11+
self.target = target
12+
for indic, i in enumerate(self.nums):
13+
for indic_b in range(indic + 1, len(nums)):
14+
if (i + nums[indic_b] == self.target):
15+
print([indic, indic_b])
16+
return ([indic, indic_b])

0 commit comments

Comments
 (0)