daily leetcode - first-missing-positive - !
题目地址 https://leetcode.com/problems/first-missing-positive/ 题目描述 Given an unsorted integer array, find the smallest missing positive integer. Example 1: Input: [1,2,0] Output: 3 Example 2: Input: [3,4,-1,1] Output: 2 Example 3: Input: [7,8,9,11,12] Output: 1 Note: Your algorithm should run in O ( n ) time and uses constant extra space. 思路 这道题让我们找缺失的首个正数,由于限定了 O(n) 的时间,所以一般的排序方法都不能用,最开始博主没有看到还限制了空间复杂度,所以想到了用 HashSet 来解,这个思路很简单,把所有的数都存入 HashSet 中,然后循环从 1 开始递增找数字,哪个数字找不到就返回哪个数字,如果一直找到了最大的数字(这里是 n....