Skip to content

Commit f29c554

Browse files
committed
two some solution
1 parent 2919348 commit f29c554

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

two-sum/devyejin.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)