Given an array of integers that's already sorted in ascending order, find, numbers such, they add up to a Specific target number.
The function twosum should return indices of the numbers such that they add up to the target, where index1 must is Les S than Index2. Please note that your returned answers (both Index1 and INDEX2) is not zero-based.
You may assume this each input would has exactly one solution.
Input: numbers={2, 7, one, target=9
Output: index1=1, index2=2
1 classsolution (object):2 deftwosum (self, Numbers, target):3 """4 : Type Numbers:list[int]5 : Type Target:int6 : Rtype:list[int]7 """8 9n =len (Numbers)Teni =0 Onej = n-1 A - whileI <J: - ifNumbers[i] + numbers[j] = =Target: the return[I+1,j+1] - elifNumbers[i] + Numbers[j] <Target: -i + = 1 - elifNumbers[i] + numbers[j] >Target: +J-= 1
Leetcode #167. Both Sum ii-input array is sorted