{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "f7d3db8318c54035bd59132cc7be4c14",
  "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": "java"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ]
  ],
  "template": {
    "content": "class Solution {\n\tpublic int firstMissingPositive(int[] nums) {\n\t\tint n = nums.length;\n\t\tint contains = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (nums[i] == 1) {\n\t\t\t\tcontains++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (contains == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif ((nums[i] <= 0) || (nums[i] > n)) {\n\t\t\t\tnums[i] = 1;\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint a = Math.abs(nums[i]);\n\t\t\tnums[a - 1] = -Math.abs(nums[a - 1]);\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (nums[i] > 0) {\n\t\t\t\treturn i + 1;\n\t\t\t}\n\t\t}\n\t\treturn n + 1;\n\t}\n}",
    "language": "java"
  },
  "node_id": "dailycode-b18ab4eee6fa4810bde94c8fdb529674",
  "license": "csdn.net",
  "created_at": 1637894159,
  "topic_link": "https://bbs.csdn.net/topics/600470223"
}