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 bcabb5c commit 292f2feCopy full SHA for 292f2fe
001_Two_Sum.py
@@ -1,15 +1,11 @@
1
-class Solution(object):
2
-
3
- def twoSum(self, nums, target):
4
- # two point
5
- nums_index = [(v, index) for index, v in enumerate(nums)]
6
- nums_index.sort()
7
- begin, end = 0, len(nums) - 1
8
- while begin < end:
9
- curr = nums_index[begin][0] + nums_index[end][0]
10
- if curr == target:
11
- return [nums_index[begin][1], nums_index[end][1]]
12
- elif curr < target:
13
- begin += 1
14
- else:
15
- end -= 1
+class Solution:
+ def twoSum(self, nums: List[int], target: int) -> List[int]:
+ result = []
+ for i in range(len(nums)-1):
+ j=i+1
+ while j < len(nums):
+ if nums[i]+nums[j]==target:
+ return [i, j]
+ j += 1
+ i += 1
+ return result
0 commit comments