{
  "type": "code_options",
  "author": "https://github.com/qiyuangong/leetcode",
  "source": "solution.md",
  "exercise_id": "1f4232c2b3234db68fb48ba078562f83",
  "keywords": "数组,哈希表",
  "title": "缺失的第一个正数",
  "desc": [
    {
      "content": "\n<p>给你一个未排序的整数数组 <code>nums</code> ，请你找出其中没有出现的最小的正整数。</p><p> </p><p><strong>进阶：</strong>你可以实现时间复杂度为 <code>O(n)</code> 并且只使用常数级别额外空间的解决方案吗？</p><p> </p><p><strong>示例 1：</strong></p><pre><strong>输入：</strong>nums = [1,2,0]<strong><br />输出：</strong>3</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>nums = [3,4,-1,1]<strong><br />输出：</strong>2</pre><p><strong>示例 3：</strong></p><pre><strong>输入：</strong>nums = [7,8,9,11,12]<strong><br />输出：</strong>1</pre><p> </p><p><strong>提示：</strong></p><ul>\t<li><code>0 <= nums.length <= 300</code></li>\t<li><code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code></li></ul>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "python"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ]
  ],
  "template": {
    "content": "class Solution(object):\n\tdef firstMissingPositive(self, nums):\n\t\tls = len(nums)\n\t\tindex = 0\n\t\twhile index < ls:\n\t\t\tif nums[index] <= 0 or nums[index] > ls or nums[nums[index] - 1] == nums[index]:\n\t\t\t\tindex += 1\n\t\t\telse:\n\t\t\t\tpos = nums[index] - 1\n\t\t\t\tnums[index], nums[pos] = nums[pos], nums[index]\n\t\tres = 0\n\t\twhile res < ls and nums[res] == res + 1:\n\t\t\tres += 1\n\t\treturn res + 1\n# %%\ns = Solution()\nprint(s.firstMissingPositive(nums = [1,2,0]))",
    "language": "python"
  },
  "node_id": "dailycode-90915356290f498093aa1edd5800a16c",
  "license": "csdn.net",
  "created_at": 1637894160,
  "topic_link": "https://bbs.csdn.net/topics/600470223"
}