|
1 | 1 | [#0167-two-sum-ii-input-array-is-sorted]
|
2 |
| -= 167. Two Sum II - Input array is sorted |
| 2 | += 167. 两数之和 II - 输入有序数组 |
3 | 3 |
|
4 |
| -{leetcode}/problems/two-sum-ii-input-array-is-sorted/[LeetCode - Two Sum II - Input array is sorted^] |
| 4 | +https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/[LeetCode - 167. 两数之和 II - 输入有序数组 ^] |
5 | 5 |
|
6 |
| -Given an array of integers that is already **sorted in ascending order**, find two numbers such that they add up to a specific target number. |
| 6 | +给你一个下标从 *1* 开始的整数数组 `numbers` ,该数组已按 *非递减顺序排列* ,请你从数组中找出满足相加之和等于目标数 `target` 的两个数。如果设这两个数分别是 `+numbers[index~1~]+` 和 `+numbers[index~2~]+` ,则 `+1 <= index~1~ < index~2~ <= numbers.length+` 。 |
7 | 7 |
|
8 |
| -The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. |
| 8 | +以长度为 2 的整数数组 `+[index~1~, index~2~]+` 的形式返回这两个整数的下标 `index~1~` 和 `index~2~`。 |
9 | 9 |
|
10 |
| -*Note:* |
| 10 | +你可以假设每个输入 *只对应唯一的答案* ,而且你 *不可以* 重复使用相同的元素。 |
11 | 11 |
|
12 |
| -* Your returned answers (both index1 and index2) are not zero-based. |
13 |
| -* You may assume that each input would have *exactly* one solution and you may not use the *same* element twice. |
| 12 | +你所设计的解决方案必须只使用常量级的额外空间。 |
| 13 | + |
| 14 | +*示例 1:* |
| 15 | + |
| 16 | +.... |
| 17 | +输入:numbers = [2,7,11,15], target = 9 |
| 18 | +输出:[1,2] |
| 19 | +解释:2 与 7 之和等于目标数 9 。因此 index1 = 1, index2 = 2 。返回 [1, 2] 。 |
| 20 | +.... |
| 21 | + |
| 22 | +*示例 2:* |
| 23 | + |
| 24 | +.... |
| 25 | +输入:numbers = [2,3,4], target = 6 |
| 26 | +输出:[1,3] |
| 27 | +解释:2 与 4 之和等于目标数 6 。因此 index1 = 1, index2 = 3 。返回 [1, 3] 。 |
| 28 | +.... |
| 29 | + |
| 30 | +*示例 3:* |
| 31 | + |
| 32 | +.... |
| 33 | +输入:numbers = [-1,0], target = -1 |
| 34 | +输出:[1,2] |
| 35 | +解释:-1 与 0 之和等于目标数 -1 。因此 index1 = 1, index2 = 2 。返回 [1, 2] 。 |
| 36 | +.... |
| 37 | + |
| 38 | + |
| 39 | +*提示:* |
| 40 | + |
| 41 | +* `2 \<= numbers.length \<= 3 * 10^4^` |
| 42 | +* `+-1000 <= numbers[i] <= 1000+` |
| 43 | +* `numbers` 按 *非递减顺序* 排列 |
| 44 | +* `+-1000 <= target <= 1000+` |
| 45 | +* *仅存在一个有效答案* |
14 | 46 |
|
15 |
| -.Example: |
16 |
| ----- |
17 |
| -Input: numbers = [2,7,11,15], target = 9 |
18 |
| -Output: [1,2] |
19 |
| -Explanation: The sum of 2 and 7 is 9. Therefore index1 = 1, index2 = 2. |
20 |
| ----- |
21 | 47 |
|
22 | 48 | == 思路分析
|
23 | 49 |
|
@@ -62,8 +88,18 @@ include::{sourcedir}/_0167_TwoSumIIInputArrayIsSorted_2.java[tag=answer]
|
62 | 88 | include::{sourcedir}/_0167_TwoSumIIInputArrayIsSorted_3.java[tag=answer]
|
63 | 89 | ----
|
64 | 90 | --
|
| 91 | +
|
| 92 | +四刷:: |
| 93 | ++ |
| 94 | +-- |
| 95 | +[{java_src_attr}] |
| 96 | +---- |
| 97 | +include::{sourcedir}/_0167_TwoSumIiInputArrayIsSorted_4.java[tag=answer] |
| 98 | +---- |
| 99 | +-- |
65 | 100 | ====
|
66 | 101 |
|
| 102 | + |
67 | 103 | == 参考资料
|
68 | 104 |
|
69 | 105 | . https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/solutions/337156/liang-shu-zhi-he-ii-shu-ru-you-xu-shu-zu-by-leet-2/[167. 两数之和 II - 输入有序数组 - 官方题解^]
|
|
0 commit comments