Leetcode 167 Solution
This article provides solution to leetcode question 167 (two-sum-ii-input-array-is-sorted)
Access this page by simply typing in "lcs 167" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/two-sum-ii-input-array-is-sorted
Solution
class Solution:
def twoSum(self, numbers: List[int], target: int) -> List[int]:
l = 0
r = len(numbers) - 1
while l < r:
if numbers[l] + numbers[r] == target:
return [l + 1, r + 1]
elif numbers[l] + numbers[r] > target:
r -= 1
else:
l += 1