{"id":3676,"date":"2023-10-28T14:39:53","date_gmt":"2023-10-28T06:39:53","guid":{"rendered":"https:\/\/white-night.club\/?p=3676"},"modified":"2023-11-09T11:07:45","modified_gmt":"2023-11-09T03:07:45","slug":"ad107","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/28\/ad107\/","title":{"rendered":"26.\u00a0\u5220\u9664\u6709\u5e8f\u6570\u7ec4\u4e2d\u7684\u91cd\u590d\u9879"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e00\u4e2a\u00a0<strong>\u975e\u4e25\u683c\u9012\u589e\u6392\u5217<\/strong>\u00a0\u7684\u6570\u7ec4\u00a0<code>nums<\/code>\u00a0\uff0c\u8bf7\u4f60<strong><a rel=\"noreferrer noopener\" href=\"http:\/\/baike.baidu.com\/item\/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95\" target=\"_blank\">\u00a0\u539f\u5730<\/a><\/strong>\u00a0\u5220\u9664\u91cd\u590d\u51fa\u73b0\u7684\u5143\u7d20\uff0c\u4f7f\u6bcf\u4e2a\u5143\u7d20\u00a0<strong>\u53ea\u51fa\u73b0\u4e00\u6b21<\/strong>\u00a0\uff0c\u8fd4\u56de\u5220\u9664\u540e\u6570\u7ec4\u7684\u65b0\u957f\u5ea6\u3002\u5143\u7d20\u7684\u00a0<strong>\u76f8\u5bf9\u987a\u5e8f<\/strong>\u00a0\u5e94\u8be5\u4fdd\u6301\u00a0<strong>\u4e00\u81f4<\/strong>\u00a0\u3002\u7136\u540e\u8fd4\u56de\u00a0<code>nums<\/code>\u00a0\u4e2d\u552f\u4e00\u5143\u7d20\u7684\u4e2a\u6570\u3002<\/p>\n\n\n\n<p>\u8003\u8651&nbsp;<code>nums<\/code>&nbsp;\u7684\u552f\u4e00\u5143\u7d20\u7684\u6570\u91cf\u4e3a&nbsp;<code>k<\/code>&nbsp;\uff0c\u4f60\u9700\u8981\u505a\u4ee5\u4e0b\u4e8b\u60c5\u786e\u4fdd\u4f60\u7684\u9898\u89e3\u53ef\u4ee5\u88ab\u901a\u8fc7\uff1a<\/p>\n\n\n\n<ul>\n<li>\u66f4\u6539\u6570\u7ec4&nbsp;<code>nums<\/code>&nbsp;\uff0c\u4f7f&nbsp;<code>nums<\/code>&nbsp;\u7684\u524d&nbsp;<code>k<\/code>&nbsp;\u4e2a\u5143\u7d20\u5305\u542b\u552f\u4e00\u5143\u7d20\uff0c\u5e76\u6309\u7167\u5b83\u4eec\u6700\u521d\u5728&nbsp;<code>nums<\/code>&nbsp;\u4e2d\u51fa\u73b0\u7684\u987a\u5e8f\u6392\u5217\u3002<code>nums<\/code>&nbsp;\u7684\u5176\u4f59\u5143\u7d20\u4e0e&nbsp;<code>nums<\/code>&nbsp;\u7684\u5927\u5c0f\u4e0d\u91cd\u8981\u3002<\/li>\n\n\n\n<li>\u8fd4\u56de&nbsp;<code>k<\/code>&nbsp;\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u5224\u9898\u6807\u51c6:<\/strong><\/p>\n\n\n\n<p>\u7cfb\u7edf\u4f1a\u7528\u4e0b\u9762\u7684\u4ee3\u7801\u6765\u6d4b\u8bd5\u4f60\u7684\u9898\u89e3:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">int[] nums = [...]; \/\/ \u8f93\u5165\u6570\u7ec4\nint[] expectedNums = [...]; \/\/ \u957f\u5ea6\u6b63\u786e\u7684\u671f\u671b\u7b54\u6848\n\nint k = removeDuplicates(nums); \/\/ \u8c03\u7528\n\nassert k == expectedNums.length;\nfor (int i = 0; i &lt; k; i++) {\n    assert nums[i] == expectedNums[i];\n}<\/pre>\n\n\n\n<p>\u5982\u679c\u6240\u6709\u65ad\u8a00\u90fd\u901a\u8fc7\uff0c\u90a3\u4e48\u60a8\u7684\u9898\u89e3\u5c06\u88ab&nbsp;<strong>\u901a\u8fc7<\/strong>\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>nums = [1,1,2]\n<strong>\u8f93\u51fa\uff1a<\/strong>2, nums = [1,2,_]\n<strong>\u89e3\u91ca\uff1a<\/strong>\u51fd\u6570\u5e94\u8be5\u8fd4\u56de\u65b0\u7684\u957f\u5ea6 <strong><code>2<\/code><\/strong> \uff0c\u5e76\u4e14\u539f\u6570\u7ec4 <em>nums <\/em>\u7684\u524d\u4e24\u4e2a\u5143\u7d20\u88ab\u4fee\u6539\u4e3a <strong><code>1<\/code><\/strong>, <strong><code>2 <\/code><\/strong><code>\u3002<\/code>\u4e0d\u9700\u8981\u8003\u8651\u6570\u7ec4\u4e2d\u8d85\u51fa\u65b0\u957f\u5ea6\u540e\u9762\u7684\u5143\u7d20\u3002\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>nums = [0,0,1,1,1,2,2,3,3,4]\n<strong>\u8f93\u51fa\uff1a<\/strong>5, nums = [0,1,2,3,4]\n<strong>\u89e3\u91ca\uff1a<\/strong>\u51fd\u6570\u5e94\u8be5\u8fd4\u56de\u65b0\u7684\u957f\u5ea6 <strong><code>5<\/code><\/strong> \uff0c \u5e76\u4e14\u539f\u6570\u7ec4 <em>nums <\/em>\u7684\u524d\u4e94\u4e2a\u5143\u7d20\u88ab\u4fee\u6539\u4e3a <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> \u3002\u4e0d\u9700\u8981\u8003\u8651\u6570\u7ec4\u4e2d\u8d85\u51fa\u65b0\u957f\u5ea6\u540e\u9762\u7684\u5143\u7d20\u3002\n<\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul>\n<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4<\/sup><\/code><\/li>\n\n\n\n<li><code>-10<sup>4<\/sup> &lt;= nums[i] &lt;= 10<sup>4<\/sup><\/code><\/li>\n\n\n\n<li><code>nums<\/code>&nbsp;\u5df2\u6309&nbsp;<strong>\u975e\u4e25\u683c\u9012\u589e<\/strong>&nbsp;\u6392\u5217<\/li>\n<\/ul>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u89e3\u9898\u601d\u8def<\/p>\n<cite><em>\u53cc\u6307\u9488<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u6709\u6bb5\u65f6\u95f4\u6ca1\u5199\u53cc\u6307\u9488\u7684\u9898\u4e86\uff0c\u8fd9\u4e0b\u771f\u7684\u662f\u6e29\u6545\u800c\u77e5\u65b0\u4e86\u3002<\/p>\n\n\n\n<p>\u4e00\u76f4\u88abreturn len\u7ed9\u9650\u5236\u4e86\uff0c\u8001\u662f\u60f3\u7740\u5728\u539f\u672c\u7684len\u4e0alen&#8211;\u3002\u4f46\u5b9e\u9645\u4e0a\u957f\u5ea6\u662f\u52a8\u6001\u53d8\u5316\u7684\uff0c\u5982\u679c\u76f4\u63a5\u5bf9len&#8211;\u90a3for\/while\u5faa\u73af\u90a3\u5757\u5c31\u4e0d\u597d\u5199\u3002\u800c\u4e14\u4e0d\u597d\u539f\u5730\u66f4\u65b0\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u7528\u6162\u6307\u9488slow\uff0c\u53ea\u8981\u6ca1\u78b0\u5230\u91cd\u590d\u5143\u7d20slow\u5c31++\uff0cfast\u6307\u9488\u8d1f\u8d23\u5c06\u540e\u9762\u4e0d\u91cd\u590d\u7684\u5143\u7d20\u5f80\u524d\u79fb\uff0c\u78b0\u5230\u91cd\u590d\u5143\u7d20++\u5c31\u884c\u3002\u6700\u540e\u8fd4\u56de\u957f\u5ea6slow\uff0c\u521a\u597d\u5c31\u662f\u6700\u540e\u4e00\u4e2a\u4e0d\u91cd\u590d\u5143\u7d20\u3002<\/p>\n\n\n\n<p>C++\u4ee5\u540e\u5b66\u670d\u52a1\u5668\u540e\u7aef\u7684\u65f6\u5019\u518d\u6162\u6162\u770b\uff0c\u73b0\u5728\u5148\u7528go\u5199\u4e86\u3002\u601d\u8def\u8fd8\u662f\u4e00\u6837\u7684\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func removeDuplicates(nums &#91;]int) int {\r\n    size:=len(nums)\r\n    if size==0{\r\n        return size\r\n    }\r\n    fast,slow:=1,1\r\n    for fast&lt;size{\r\n        if nums&#91;fast]!=nums&#91;fast-1]{\r\n            nums&#91;slow]=nums&#91;fast]\r\n            slow++\r\n        }\r\n        fast++\r\n    }\r\n    return slow\r\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u53cc\u6307\u9488<\/p>\n","protected":false},"author":1,"featured_media":2827,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[42,25],"tags":[38],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3676"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=3676"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3676\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/2827"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=3676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=3676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=3676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}