Skip to content

Commit af03921

Browse files
committed
#167: Two Sum II - Input Array is Sorted
1 parent 06a066f commit af03921

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Two_Pointers/two_sumsII.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
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.
48
# Your solution must use only constant extra space.
59

610

711
# Example 1:
8-
912
# Input: numbers = [2,7,11,15], target = 9
1013
# Output: [1,2]
1114
# Explanation: The sum of 2 and 7 is 9. Therefore, index1 = 1, index2 = 2. We return [1, 2].
12-
# Example 2:
1315

16+
# Example 2:
1417
# Input: numbers = [2,3,4], target = 6
1518
# Output: [1,3]
1619
# Explanation: The sum of 2 and 4 is 6. Therefore index1 = 1, index2 = 3. We return [1, 3].
17-
# Example 3:
1820

21+
# Example 3:
1922
# Input: numbers = [-1,0], target = -1
2023
# Output: [1,2]
2124
# Explanation: The sum of -1 and 0 is -1. Therefore index1 = 1, index2 = 2. We return [1, 2].

0 commit comments

Comments
 (0)