{"id":5296,"date":"2023-11-18T14:16:07","date_gmt":"2023-11-18T06:16:07","guid":{"rendered":"https:\/\/white-night.club\/?p=5296"},"modified":"2023-11-18T14:19:20","modified_gmt":"2023-11-18T06:19:20","slug":"ad155","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/11\/18\/ad155\/","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 href=\"http:\/\/baike.baidu.com\/item\/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95\" target=\"_blank\" rel=\"noreferrer noopener\">\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:int[] nums = [&#8230;]; \/\/ \u8f93\u5165\u6570\u7ec4 int[] expectedNums = [&#8230;]; \/\/ \u957f\u5ea6\u6b63\u786e\u7684\u671f\u671b\u7b54\u6848 int k = removeDuplicates(nums); \/\/ \u8c03\u7528 assert k == expectedNums.length; for (int i = 0; i &lt; k; i++) { assert nums[i] == expectedNums[i]; }<\/p>\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><strong>\u8f93\u5165\uff1a<\/strong>nums = [1,1,2] <strong>\u8f93\u51fa\uff1a<\/strong>2, nums = [1,2,_] <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<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><strong>\u8f93\u5165\uff1a<\/strong>nums = [0,0,1,1,1,2,2,3,3,4] <strong>\u8f93\u51fa\uff1a<\/strong>5, nums = [0,1,2,3,4] <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<\/p>\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 has-link-color wp-elements-db7d1dcdabd125fe3cb1cd106e289972\">\n<p>\u89e3\u9898\u601d\u8def<\/p>\n<cite><em>\u53cc\u6307\u9488<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u548c\u201c\u539f\u5730\u5220\u9664\u503c\u4e3aval\u201d\u7684\u9898\u5f88\u50cf\u3002\u5927\u81f4\u601d\u8def\u4e5f\u8fd8\u662f\u7528\u53cc\u6307\u9488\u53bb\u505a\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&lt;=1{\r\n        return size\r\n    }\r\n    left,right:=1,1\r\n    for right&lt;size{\r\n        if nums&#91;right]!=nums&#91;right-1]{\r\n            nums&#91;left]=nums&#91;right]\r\n            left++\r\n        }\r\n        right++\r\n    }\r\n    return left\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\/5296"}],"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=5296"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/5296\/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=5296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=5296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=5296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}