|
1 |
| -# Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 <= index1 < index2 <= numbers.length. |
2 |
| -# Return the indices of the two numbers, index1 and index2, added by one as an integer array [index1, index2] of length 2. |
3 |
| -# The tests are generated such that there is exactly one solution. You may not use the same element twice. |
| 1 | +# Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, |
| 2 | +# find two numbers such that they add up to a specific target number. Let these two numbers be |
| 3 | +# numbers[index1] and numbers[index2] where 1 <= index1 < index2 <= numbers.length. |
| 4 | +# Return the indices of the two numbers, index1 and index2, added by one as an integer array |
| 5 | +# [index1, index2] of length 2. |
| 6 | +# The tests are generated such that there is exactly one solution. You may not use the same |
| 7 | +# element twice. |
4 | 8 | # Your solution must use only constant extra space.
|
5 | 9 |
|
6 | 10 |
|
7 | 11 | # Example 1:
|
8 |
| - |
9 | 12 | # Input: numbers = [2,7,11,15], target = 9
|
10 | 13 | # Output: [1,2]
|
11 | 14 | # Explanation: The sum of 2 and 7 is 9. Therefore, index1 = 1, index2 = 2. We return [1, 2].
|
12 |
| -# Example 2: |
13 | 15 |
|
| 16 | +# Example 2: |
14 | 17 | # Input: numbers = [2,3,4], target = 6
|
15 | 18 | # Output: [1,3]
|
16 | 19 | # Explanation: The sum of 2 and 4 is 6. Therefore index1 = 1, index2 = 3. We return [1, 3].
|
17 |
| -# Example 3: |
18 | 20 |
|
| 21 | +# Example 3: |
19 | 22 | # Input: numbers = [-1,0], target = -1
|
20 | 23 | # Output: [1,2]
|
21 | 24 | # Explanation: The sum of -1 and 0 is -1. Therefore index1 = 1, index2 = 2. We return [1, 2].
|
|
0 commit comments