mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-06 07:51:41 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你一个 <strong>非严格递增排列</strong> 的数组 <code>nums</code> ,请你<strong><a href=\"http://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95\" target=\"_blank\"> 原地</a></strong> 删除重复出现的元素,使每个元素 <strong>只出现一次</strong> ,返回删除后数组的新长度。元素的 <strong>相对顺序</strong> 应该保持 <strong>一致</strong> 。然后返回 <code>nums</code> 中唯一元素的个数。</p>\n\n<p>考虑 <code>nums</code> 的唯一元素的数量为 <code>k</code> ,你需要做以下事情确保你的题解可以被通过:</p>\n\n<ul>\n\t<li>更改数组 <code>nums</code> ,使 <code>nums</code> 的前 <code>k</code> 个元素包含唯一元素,并按照它们最初在 <code>nums</code> 中出现的顺序排列。<code>nums</code> 的其余元素与 <code>nums</code> 的大小不重要。</li>\n\t<li>返回 <code>k</code> 。</li>\n</ul>\n\n<p><strong>判题标准:</strong></p>\n\n<p>系统会用下面的代码来测试你的题解:</p>\n\n<pre>\nint[] nums = [...]; // 输入数组\nint[] expectedNums = [...]; // 长度正确的期望答案\n\nint k = removeDuplicates(nums); // 调用\n\nassert k == expectedNums.length;\nfor (int i = 0; i < k; i++) {\n assert nums[i] == expectedNums[i];\n}</pre>\n\n<p>如果所有断言都通过,那么您的题解将被 <strong>通过</strong>。</p>\n\n<p> </p>\n\n<p><strong class=\"example\">示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1,1,2]\n<strong>输出:</strong>2, nums = [1,2,_]\n<strong>解释:</strong>函数应该返回新的长度 <strong><code>2</code></strong> ,并且原数组 <em>nums </em>的前两个元素被修改为 <strong><code>1</code></strong>, <strong><code>2 </code></strong><code>。</code>不需要考虑数组中超出新长度后面的元素。\n</pre>\n\n<p><strong class=\"example\">示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [0,0,1,1,1,2,2,3,3,4]\n<strong>输出:</strong>5, nums = [0,1,2,3,4]\n<strong>解释:</strong>函数应该返回新的长度 <strong><code>5</code></strong> , 并且原数组 <em>nums </em>的前五个元素被修改为 <strong><code>0</code></strong>, <strong><code>1</code></strong>, <strong><code>2</code></strong>, <strong><code>3</code></strong>, <strong><code>4</code></strong> 。不需要考虑数组中超出新长度后面的元素。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 3 * 10<sup>4</sup></code></li>\n\t<li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li>\n\t<li><code>nums</code> 已按 <strong>非严格递增</strong> 排列</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Easy",
|
||||
"likes": 3414,
|
||||
"likes": 3415,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[{\"title\": \"Remove Element\", \"titleSlug\": \"remove-element\", \"difficulty\": \"Easy\", \"translatedTitle\": \"\\u79fb\\u9664\\u5143\\u7d20\", \"isPaidOnly\": false}, {\"title\": \"Remove Duplicates from Sorted Array II\", \"titleSlug\": \"remove-duplicates-from-sorted-array-ii\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u5220\\u9664\\u6709\\u5e8f\\u6570\\u7ec4\\u4e2d\\u7684\\u91cd\\u590d\\u9879 II\", \"isPaidOnly\": false}]",
|
||||
@@ -137,7 +137,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"1.7M\", \"totalSubmission\": \"3M\", \"totalAcceptedRaw\": 1684784, \"totalSubmissionRaw\": 3039768, \"acRate\": \"55.4%\"}",
|
||||
"stats": "{\"totalAccepted\": \"1.7M\", \"totalSubmission\": \"3M\", \"totalAcceptedRaw\": 1685016, \"totalSubmissionRaw\": 3040111, \"acRate\": \"55.4%\"}",
|
||||
"hints": [
|
||||
"In this problem, the key point to focus on is the input array being sorted. As far as duplicate elements are concerned, what is their positioning in the array when the given array is sorted? Look at the image above for the answer. If we know the position of one of the elements, do we also know the positioning of all the duplicate elements?\r\n\r\n<br>\r\n<img src=\"https://assets.leetcode.com/uploads/2019/10/20/hint_rem_dup.png\" width=\"500\"/>",
|
||||
"We need to modify the array in-place and the size of the final array would potentially be smaller than the size of the input array. So, we ought to use a two-pointer approach here. One, that would keep track of the current element in the original array and another one for just the unique elements.",
|
||||
|
Reference in New Issue
Block a user