{"id":2818,"date":"2020-01-27T12:01:55","date_gmt":"2020-01-27T04:01:55","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=2818"},"modified":"2020-01-27T12:01:55","modified_gmt":"2020-01-27T04:01:55","slug":"%e3%80%90leetcode%e3%80%910026-%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\/2818\/","title":{"rendered":"\u3010LeetCode\u30110026 \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\/\">https:\/\/leetcode-cn.com\/problems\/remove-duplicates-from-sorted-array\/<\/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):\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>for i in range(len(nums) - 1, 0, -1):\n            if nums[i] == nums[i - 1]:\n                nums.pop(i)\n        return len(nums)\nif __name__ == '__main__':\n    nums = [1, 1, 2]\n    print(Solution().removeDuplicates(nums))\n<\/pre>\n\n\n<p><strong>\u601d\u8def<\/strong>\uff1a\u56e0\u4e3a\u8981\u8fd4\u56denums\u7684\u5f15\u7528\uff0c\u6240\u4ee5\u53ea\u80fd\u5728\u539f\u53d8\u91cf\u4e0a\u8fdb\u884c\u64cd\u4f5c\uff0c\u56e0\u6b64\u4e0d\u53ef\u4ee5\u4f7f\u7528set\u53bb\u91cd\uff0c\u6211\u4eec\u5faa\u73af\u68c0\u67e5\u662f\u5426\u4e0e\u4e0a\u4e00\u4f4d\u76f8\u540c\uff0c\u7136\u540epop\u6389\u5f53\u524d\u5143\u7d20\u3002<\/p>\n\n\n<p>\u8fd9\u91cc\u4f7f\u7528\u5012\u5e8f\u7684\u539f\u56e0\u662f\u5982\u679c\u662f\u6b63\u5e8f\u5220\u6389\u5143\u7d20\u4e4b\u540e\u4f1a\u6f0f\u67e5\u5e76\u4e14\u4f1a\u6ea2\u51fa\uff08\u53c8\u56e0\u4e3apython\u7684for\u5faa\u73af\u4e2d\u5bf9i\u7684\u66f4\u6539\u4e0d\u4f1a\u5b9e\u9645\u4e0a\u6539\u53d8\u5faa\u73af\u4e2d\u7684i\uff0c<strong>\u5177\u4f53\u539f\u56e0\u6211\u4e5f\u4e0d\u662f\u5f88\u6e05\u695a\uff0c\u67e5\u4e86\u4e00\u5927\u5708\uff0c\u4e5f\u53ea\u662f\u5927\u6982\u77e5\u9053for\u5faa\u73af\u662f\u4e00\u4e2a\u6709\u7740\u5355\u72ec\u7ebf\u7a0b\u9501\u7684\u5bb9\u5668\uff0c\u5bf9i\u7684\u66f4\u6539\u4e0d\u4f1a\u9020\u6210\u5b9e\u9645i\u7684\u6539\u53d8\uff0c\u5982\u679c\u6709\u77e5\u9053\u66f4\u8be6\u7ec6\u539f\u56e0\u7684\u5927\u4f6c\u8fd8\u5e0c\u671b\u6307\u6559<\/strong>\uff09\u4f46\u662f\u5012\u5e8f\u5c31\u4e0d\u4e00\u6837\u4e86\uff0c\u5012\u5e8f\u65e0\u975e\u662f\u591a\u6bd4\u8f83\u4e00\u6b21\uff0c\u4e0d\u4f1a\u9020\u6210\u4e0a\u6ea2\u7684\u95ee\u9898\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":1515,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2818"}],"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=2818"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2818\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2818"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}