{"id":3114,"date":"2020-03-04T12:08:34","date_gmt":"2020-03-04T04:08:34","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=3114"},"modified":"2020-03-04T12:08:34","modified_gmt":"2020-03-04T04:08:34","slug":"%e3%80%90leetcode%e3%80%910080-%e5%88%a0%e9%99%a4%e6%8e%92%e5%ba%8f%e6%95%b0%e7%bb%84%e4%b8%ad%e7%9a%84%e9%87%8d%e5%a4%8d%e9%a1%b9","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/algorithm\/3114\/","title":{"rendered":"\u3010LeetCode\u30110080 \u5220\u9664\u6392\u5e8f\u6570\u7ec4\u4e2d\u7684\u91cd\u590d\u9879"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/remove-duplicates-from-sorted-array-ii\/\">https:\/\/leetcode-cn.com\/problems\/remove-duplicates-from-sorted-array-ii\/<\/a><\/p>\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding:utf-8 -*-\n<em>\n<\/em>class Solution(object):\n    def removeDuplicates(self, nums: list):\n        <em>\"\"\"\n        <\/em><strong><em>:type<\/em><\/strong><em> nums: List[int]\n        <\/em><strong><em>:rtype<\/em><\/strong><em>: int\n        \"\"\"\n        <\/em>if len(nums) == 0:\n            return 0\n        flag_nub = nums[0]\n        flag_times = 0\n        current_idx = 0\n        while len(nums) > 0:\n            if current_idx == len(nums):\n                return len(nums)\n            if flag_nub == nums[current_idx] and flag_times &lt; 2:\n                flag_times += 1\n            elif flag_nub == nums[current_idx]:\n                nums.remove(nums[current_idx])\n                current_idx -= 1\n            else:\n                flag_times = 1\n                flag_nub = nums[current_idx]\n            current_idx += 1\n        return len(nums)\nif __name__ == '__main__':\n    nums = [1, 1, 1, 2, 2, 3]\n    nums = [0, 0, 1, 1, 1, 1, 2, 3, 3]\n    print(Solution().removeDuplicates(nums))\n<\/pre>\n\n\n<p><strong>\u601d\u8def<\/strong>\uff1a\u8fd9\u9053\u9898\u5176\u5b9e\u601d\u8def\u4e0d\u96be\uff0c\u65e0\u975e\u662f\u904d\u5386\u4e00\u4e0b\uff0c\u7136\u540e\u7528\u4e00\u4e2a\u53d8\u91cf\u6807\u8bb0\u91cd\u590d\u51fa\u73b02\u6b21\u4ee5\u4e0a\u7684\u5143\u7d20\u8fdb\u884c\u5220\u9664\u3002<\/p>\n\n\n<p>\u4f46\u662f\u6709\u4e00\u4e2a\u95ee\u9898\u662fpython for\u7684\u8fed\u4ee3\u5668\u673a\u5236\uff08\u4e4b\u524d\u5df2\u7ecf\u63d0\u8fc7\uff09\uff0c\u5bfc\u81f4\u5982\u679c\u5728for\u5faa\u73af\u4e2d\u5bf9\u5217\u8868\u8fdb\u884c\u589e\u5220\u64cd\u4f5c\u4f1a\u5bfc\u81f4\u5f02\u5e38\uff0c\u56e0\u6b64\u8fd9\u91cc\u9700\u8981\u518d\u5f15\u5165\u4e00\u4e2a\u53d8\u91cf\u4f7f\u7528while\u5faa\u73af\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode-cn.com\/problems\/remove-duplicates [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[10],"tags":[],"views":3089,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/3114"}],"collection":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/comments?post=3114"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/3114\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=3114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=3114"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=3114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}