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 3bbbd04 commit 593590dCopy full SHA for 593590d
06--greedy/ragdoll/neetcode/two_sum.py
@@ -0,0 +1,23 @@
1
+from typing import List
2
+
3
4
+class Solution:
5
+ def twoSum(self, nums: List[int], target: int) -> List[int]:
6
+ numbers = sorted(nums)
7
+ left = 0
8
+ right = len(numbers) - 1
9
10
+ while left < right:
11
+ sum = numbers[left] + numbers[right]
12
+ if sum == target:
13
+ if numbers[left] == numbers[right]:
14
+ left_index = nums.index(numbers[left])
15
+ right_index = nums.index(numbers[right], left_index + 1)
16
+ return [left_index, right_index]
17
+ else:
18
+ return [nums.index(numbers[left]), nums.index(numbers[right])]
19
20
+ if sum < target:
21
+ left += 1
22
+ elif sum > target:
23
+ right -= 1
0 commit comments