{"id":2883,"date":"2020-02-05T14:20:38","date_gmt":"2020-02-05T06:20:38","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=2883"},"modified":"2020-02-05T14:20:38","modified_gmt":"2020-02-05T06:20:38","slug":"%e3%80%90leetcode%e3%80%910041-%e7%bc%ba%e5%a4%b1%e7%9a%84%e7%ac%ac%e4%b8%80%e4%b8%aa%e6%ad%a3%e6%95%b0","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/algorithm\/2883\/","title":{"rendered":"\u3010LeetCode\u30110041 \u7f3a\u5931\u7684\u7b2c\u4e00\u4e2a\u6b63\u6570"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/first-missing-positive\/\">https:\/\/leetcode-cn.com\/problems\/first-missing-positive\/<\/a><\/p>\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding:utf-8 -*-\n<em>\n<\/em>class Solution(object):\n    def firstMissingPositive(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>n = len(nums)\n        temp_list = [0 for _ in range(n)]\n        for each in nums:\n            if each &lt;= n and each > 0:\n                temp_list[each - 1] = each\n        for i in range(n):\n            if temp_list[i] != i + 1:\n                return i + 1\n        return n + 1\nif __name__ == '__main__':\n    nums = [1]\n    print(Solution().firstMissingPositive(nums))\n<\/pre>\n\n\n<p><strong>\u601d\u8def<\/strong>\uff1a\u8fd9\u9053\u9898\u9996\u5148\u751f\u6210\u4e00\u4e2a\u957f\u5ea6\u4e3an\u7684\u5217\u8868\uff0c\u7136\u540e\u904d\u5386\u6574\u4e2a\u6570\u7ec4\uff0c\u5c06>0\u5e76\u4e14&lt;n\u7684\u6570\u5b57\u653e\u5165\u5217\u8868\u4e2d\uff0c\u5982\u679c\u6709\u4f4d\u7f6e\u4e3a\u521d\u59cb\u503c0\uff0c\u5219\u8bf4\u660e\u7f3a\u5c11\u8fd9\u4e2a\uff0c\u5982\u679c\u5217\u8868\u6ca1\u6709\u7f3a\u5931\u4f4d\u7f6e\uff0c\u5219\u8bf4\u660e\u7f3a\u5931\u503c\u4e3an+1\u3002<\/p>\n\n\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u7a7a\u95f4\u548c\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u4e3aO(n)\u3002\u4f46\u662f\u9898\u91cc\u8bf4\u7ebf\u6027\u7a7a\u95f4\uff0c\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u63d0\u524d\u904d\u5386\u4e00\u904d\u6570\u7ec4\uff0c\u6c42\u51fa\u6b63\u6570\u548c\u4e2a\u6570\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u628an\u7f29\u5c0f\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e5f\u5c06\u4e3a\u4e86\u5e38\u6570\u3002<\/p>\n\n\n<p>\u8fd9\u662f\u5178\u578b\u7684\u65f6\u95f4\u6362\u7a7a\u95f4\u7684\u505a\u6cd5\uff0c\u5b9e\u9645\u4e0a\u4e0d\u505a\u5904\u7406\u4e5f\u53ef\u4ee5\u8fbe\u5230\u4e00\u4e2a\u5f88\u597d\u7684\u6548\u679c\u3002<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"422\" height=\"92\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-27.png\" alt=\"\" class=\"wp-image-2884\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-27.png 422w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-27-300x65.png 300w\" sizes=\"(max-width: 422px) 100vw, 422px\" \/><\/figure><\/div>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode-cn.com\/problems\/first-missing-pos [&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":1382,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2883"}],"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=2883"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2883\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2883"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}