题解 | #缺失的第一个正整数#
缺失的第一个正整数
https://www.nowcoder.com/practice/50ec6a5b0e4e45348544348278cdcee5
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * *1 2 3 5 6 * 1 3 4 5 * 3 4 5 * @param nums int整型一维数组 * @return int整型 */ public int minNumberDisappeared (int[] nums) { Map<Integer, Integer> r = new HashMap<>(); // 先排序放入map Arrays.stream(nums).sorted().forEach(x-> r.put(x, 1)); //从1开始比较,不包含直接返回最小值 int compTemp = 1; while (r.containsKey(compTemp)) { compTemp++; } return compTemp; // write code here } }