We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0ccc833 commit f33a26fCopy full SHA for f33a26f
1 file changed
LeetCode/TwoSum_1.py
@@ -0,0 +1,29 @@
1
+class Solution:
2
+ def twoSum(self, nums, target):
3
+ """
4
+ :type nums: List[int]
5
+ :type target: int
6
+ :rtype: List[int]
7
8
+ s = sorted(nums)
9
+ l = 0
10
+ r = len(s) - 1
11
+
12
+ while l < r:
13
+ t = s[r] + s[l]
14
+ if t == target:
15
+ al = s[l]
16
+ ar = s[r]
17
+ break
18
+ elif t > target:
19
+ r -= 1
20
+ if l < r and s[r] == s[r + 1]:
21
22
+ else:
23
+ l += 1
24
+ if l < r and s[l] == s[l - 1]:
25
26
+ l = nums.index(al)
27
+ nums.reverse()
28
+ r = len(nums) - 1 - nums.index(ar)
29
+ return sorted([l, r])
0 commit comments