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 2919348 commit f29c554Copy full SHA for f29c554
two-sum/devyejin.py
@@ -0,0 +1,17 @@
1
+class Solution(object):
2
+ def twoSum(self, nums, target):
3
+
4
+ nums_tuple = sorted(list(enumerate(nums)), key=lambda x: x[1])
5
+ left, right = 0, len(nums) - 1
6
7
+ while left < right:
8
+ temp_sum = nums_tuple[left][1] + nums_tuple[right][1]
9
+ if temp_sum == target:
10
+ return [nums_tuple[left][0], nums_tuple[right][0]]
11
+ elif temp_sum < target:
12
+ left += 1
13
+ else:
14
+ right -= 1
15
16
17
0 commit comments