mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 07:21:40 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你两个按 <strong>非递减顺序</strong> 排列的整数数组 <code>nums1</code><em> </em>和 <code>nums2</code>,另有两个整数 <code>m</code> 和 <code>n</code> ,分别表示 <code>nums1</code> 和 <code>nums2</code> 中的元素数目。</p>\n\n<p>请你 <strong>合并</strong> <code>nums2</code><em> </em>到 <code>nums1</code> 中,使合并后的数组同样按 <strong>非递减顺序</strong> 排列。</p>\n\n<p><strong>注意:</strong>最终,合并后数组不应由函数返回,而是存储在数组 <code>nums1</code> 中。为了应对这种情况,<code>nums1</code> 的初始长度为 <code>m + n</code>,其中前 <code>m</code> 个元素表示应合并的元素,后 <code>n</code> 个元素为 <code>0</code> ,应忽略。<code>nums2</code> 的长度为 <code>n</code> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3\n<strong>输出:</strong>[1,2,2,3,5,6]\n<strong>解释:</strong>需要合并 [1,2,3] 和 [2,5,6] 。\n合并结果是 [<em><strong>1</strong></em>,<em><strong>2</strong></em>,2,<em><strong>3</strong></em>,5,6] ,其中斜体加粗标注的为 nums1 中的元素。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>nums1 = [1], m = 1, nums2 = [], n = 0\n<strong>输出:</strong>[1]\n<strong>解释:</strong>需要合并 [1] 和 [] 。\n合并结果是 [1] 。\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre>\n<strong>输入:</strong>nums1 = [0], m = 0, nums2 = [1], n = 1\n<strong>输出:</strong>[1]\n<strong>解释:</strong>需要合并的数组是 [] 和 [1] 。\n合并结果是 [1] 。\n注意,因为 m = 0 ,所以 nums1 中没有元素。nums1 中仅存的 0 仅仅是为了确保合并结果可以顺利存放到 nums1 中。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>nums1.length == m + n</code></li>\n\t<li><code>nums2.length == n</code></li>\n\t<li><code>0 <= m, n <= 200</code></li>\n\t<li><code>1 <= m + n <= 200</code></li>\n\t<li><code>-10<sup>9</sup> <= nums1[i], nums2[j] <= 10<sup>9</sup></code></li>\n</ul>\n\n<p> </p>\n\n<p><strong>进阶:</strong>你可以设计实现一个时间复杂度为 <code>O(m + n)</code> 的算法解决此问题吗?</p>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Easy",
|
||||
"likes": 1359,
|
||||
"likes": 1408,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[{\"title\": \"Merge Two Sorted Lists\", \"titleSlug\": \"merge-two-sorted-lists\", \"difficulty\": \"Easy\", \"translatedTitle\": \"\\u5408\\u5e76\\u4e24\\u4e2a\\u6709\\u5e8f\\u94fe\\u8868\"}, {\"title\": \"Squares of a Sorted Array\", \"titleSlug\": \"squares-of-a-sorted-array\", \"difficulty\": \"Easy\", \"translatedTitle\": \"\\u6709\\u5e8f\\u6570\\u7ec4\\u7684\\u5e73\\u65b9\"}, {\"title\": \"Interval List Intersections\", \"titleSlug\": \"interval-list-intersections\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u533a\\u95f4\\u5217\\u8868\\u7684\\u4ea4\\u96c6\"}]",
|
||||
@@ -137,7 +137,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"611K\", \"totalSubmission\": \"1.2M\", \"totalAcceptedRaw\": 611009, \"totalSubmissionRaw\": 1170851, \"acRate\": \"52.2%\"}",
|
||||
"stats": "{\"totalAccepted\": \"640.3K\", \"totalSubmission\": \"1.2M\", \"totalAcceptedRaw\": 640306, \"totalSubmissionRaw\": 1225799, \"acRate\": \"52.2%\"}",
|
||||
"hints": [
|
||||
"You can easily solve this problem if you simply think about two elements at a time rather than two arrays. We know that each of the individual arrays is sorted. What we don't know is how they will intertwine. Can we take a local decision and arrive at an optimal solution?",
|
||||
"If you simply consider one element each at a time from the two arrays and make a decision and proceed accordingly, you will arrive at the optimal solution."
|
||||
|
Reference in New Issue
Block a user