We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 292f2fe commit a80797bCopy full SHA for a80797b
001_Two_Sum.py
@@ -1,11 +1,17 @@
1
class Solution:
2
def twoSum(self, nums: List[int], target: int) -> List[int]:
3
- result = []
4
- for i in range(len(nums)-1):
5
- j=i+1
6
- while j < len(nums):
7
- if nums[i]+nums[j]==target:
8
- return [i, j]
9
- j += 1
10
- i += 1
11
- return result
+ # nums_index = list(enumerate(nums))
+ # nums_index.sort()
+ # print(nums)
+ for i in range(len(nums)):
+ complement = target-nums[i]
+ if complement in nums and nums.index(complement) != i:
+ return [i,nums.index(complement)]
+ # for i in range(len(nums)-1):
+ # j=i+1
12
+ # while j < len(nums):
13
+ # if nums[i]+nums[j]==target:
14
+ # return [i, j]
15
+ # j += 1
16
+ # i += 1
17
+ # return result
0 commit comments