|
4 | 4 |
|
5 | 5 | ## 题目 |
6 | 6 |
|
7 | | -Given an array of integers `nums` and an integer `target`, return _indices of |
8 | | -the two numbers such that they add up to`target`_. |
| 7 | +<p>给定一个整数数组 <code>nums</code> 和一个整数目标值 <code>target</code>,请你在该数组中找出 <strong>和为目标值 </strong><em><code>target</code></em> 的那 <strong>两个</strong> 整数,并返回它们的数组下标。</p> |
9 | 8 |
|
10 | | -You may assume that each input would have **_exactly_ one solution**, and you |
11 | | -may not use the _same_ element twice. |
| 9 | +<p>你可以假设每种输入只会对应一个答案,并且你不能使用两次相同的元素。</p> |
12 | 10 |
|
13 | | -You can return the answer in any order. |
| 11 | +<p>你可以按任意顺序返回答案。</p> |
14 | 12 |
|
| 13 | +<p> </p> |
15 | 14 |
|
| 15 | +<p><strong class="example">示例 1:</strong></p> |
16 | 16 |
|
17 | | -**Example 1:** |
| 17 | +<pre> |
| 18 | +<strong>输入:</strong>nums = [2,7,11,15], target = 9 |
| 19 | +<strong>输出:</strong>[0,1] |
| 20 | +<strong>解释:</strong>因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。 |
| 21 | +</pre> |
18 | 22 |
|
19 | | -> Input: nums = [2,7,11,15], target = 9 |
20 | | -> |
21 | | -> Output: [0,1] |
22 | | -> |
23 | | -> Explanation: Because nums[0] + nums[1] == 9, we return [0, 1]. |
| 23 | +<p><strong class="example">示例 2:</strong></p> |
24 | 24 |
|
25 | | -**Example 2:** |
| 25 | +<pre> |
| 26 | +<strong>输入:</strong>nums = [3,2,4], target = 6 |
| 27 | +<strong>输出:</strong>[1,2] |
| 28 | +</pre> |
26 | 29 |
|
27 | | -> Input: nums = [3,2,4], target = 6 |
28 | | -> |
29 | | -> Output: [1,2] |
| 30 | +<p><strong class="example">示例 3:</strong></p> |
30 | 31 |
|
31 | | -**Example 3:** |
| 32 | +<pre> |
| 33 | +<strong>输入:</strong>nums = [3,3], target = 6 |
| 34 | +<strong>输出:</strong>[0,1] |
| 35 | +</pre> |
32 | 36 |
|
33 | | -> Input: nums = [3,3], target = 6 |
34 | | -> |
35 | | -> Output: [0,1] |
| 37 | +<p> </p> |
36 | 38 |
|
37 | | -**Constraints:** |
| 39 | +<p><strong>提示:</strong></p> |
38 | 40 |
|
39 | | - * `2 <= nums.length <= 10^4` |
40 | | - * `-10^9 <= nums[i] <= 10^9` |
41 | | - * `-10^9 <= target <= 10^9` |
42 | | - * **Only one valid answer exists.** |
| 41 | +<ul> |
| 42 | + <li><code>2 <= nums.length <= 10<sup>4</sup></code></li> |
| 43 | + <li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li> |
| 44 | + <li><code>-10<sup>9</sup> <= target <= 10<sup>9</sup></code></li> |
| 45 | + <li><strong>只会存在一个有效答案</strong></li> |
| 46 | +</ul> |
43 | 47 |
|
| 48 | +<p> </p> |
44 | 49 |
|
45 | | - |
46 | | -**Follow-up: **Can you come up with an algorithm that is less than `O(n2)` |
47 | | -time complexity? |
48 | | - |
49 | | - |
50 | | -## 题目大意 |
51 | | - |
52 | | -给定一个整数数组 `nums` 和一个整数目标值 `target`,请你在该数组中找出 **和为目标值** _`target`_ 的那 **两个** |
53 | | -整数,并返回它们的数组下标。 |
54 | | - |
55 | | -你可以假设每种输入只会对应一个答案,并且你不能使用两次相同的元素。 |
56 | | - |
57 | | -你可以按任意顺序返回答案。 |
58 | | - |
59 | | - |
60 | | - |
61 | | -**示例 1:** |
62 | | - |
63 | | -> |
64 | | -> |
65 | | -> |
66 | | -> |
67 | | -> |
68 | | -> **输入:** nums = [2,7,11,15], target = 9 |
69 | | -> |
70 | | -> **输出:**[0,1] |
71 | | -> |
72 | | -> **解释:** 因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。 |
73 | | -> |
74 | | -> |
75 | | -
|
76 | | -**示例 2:** |
77 | | - |
78 | | -> |
79 | | -> |
80 | | -> |
81 | | -> |
82 | | -> |
83 | | -> **输入:** nums = [3,2,4], target = 6 |
84 | | -> |
85 | | -> **输出:**[1,2] |
86 | | -> |
87 | | -> |
88 | | -
|
89 | | -**示例 3:** |
90 | | - |
91 | | -> |
92 | | -> |
93 | | -> |
94 | | -> |
95 | | -> |
96 | | -> **输入:** nums = [3,3], target = 6 |
97 | | -> |
98 | | -> **输出:**[0,1] |
99 | | -> |
100 | | -> |
101 | | -
|
102 | | - |
103 | | - |
104 | | -**提示:** |
105 | | - |
106 | | - * `2 <= nums.length <= 10^4` |
107 | | - * `-10^9 <= nums[i] <= 10^9` |
108 | | - * `-10^9 <= target <= 10^9` |
109 | | - * **只会存在一个有效答案** |
110 | | - |
111 | | - |
112 | | - |
113 | | -**进阶:** 你可以想出一个时间复杂度小于 `O(n2)` 的算法吗? |
| 50 | +<p><strong>进阶:</strong>你可以想出一个时间复杂度小于 <code>O(n<sup>2</sup>)</code> 的算法吗?</p> |
114 | 51 |
|
115 | 52 |
|
116 | 53 | ## 解题思路 |
@@ -138,7 +75,7 @@ time complexity? |
138 | 75 | | 560 | [和为 K 的子数组](https://leetcode.com/problems/subarray-sum-equals-k) | [[✓]](/problem/0560.md) | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`前缀和`](/tag/prefix-sum.md) | <font color=#ffb800>Medium</font> | |
139 | 76 | | 653 | [两数之和 IV - 输入二叉搜索树](https://leetcode.com/problems/two-sum-iv-input-is-a-bst) | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `4+` | <font color=#15bd66>Easy</font> | |
140 | 77 | | 1099 | [小于 K 的两数之和](https://leetcode.com/problems/two-sum-less-than-k) | | [`数组`](/tag/array.md) [`双指针`](/tag/two-pointers.md) [`二分查找`](/tag/binary-search.md) `1+` | <font color=#15bd66>Easy</font> | |
141 | | -| 1679 | [K 和数对的最大数目](https://leetcode.com/problems/max-number-of-k-sum-pairs) | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`双指针`](/tag/two-pointers.md) `1+` | <font color=#ffb800>Medium</font> | |
| 78 | +| 1679 | [K 和数对的最大数目](https://leetcode.com/problems/max-number-of-k-sum-pairs) | [[✓]](/problem/1679.md) | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`双指针`](/tag/two-pointers.md) `1+` | <font color=#ffb800>Medium</font> | |
142 | 79 | | 1711 | [大餐计数](https://leetcode.com/problems/count-good-meals) | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) | <font color=#ffb800>Medium</font> | |
143 | 80 | | 2006 | [差的绝对值为 K 的数对数目](https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k) | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`计数`](/tag/counting.md) | <font color=#15bd66>Easy</font> | |
144 | 81 | | 2023 | [连接后等于目标字符串的字符串对](https://leetcode.com/problems/number-of-pairs-of-strings-with-concatenation-equal-to-target) | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) `1+` | <font color=#ffb800>Medium</font> | |
|
0 commit comments