算法 哈希-缺失的第一个正整数 求解代码 1 2 3 4 5 6 7 8 9 10 11 public int minNumberDisappeared (int[] nums) { HashSet<Integer> set = new HashSet<>(); for (int i = 0; i < nums.length; i++) { set.add(nums[i]); } int res = 1; while (set.contains(res)) { res++; } return res; } 小贴士 利用HashSet的O (1) 快速查找特性,先把数组所有元素存入哈希表 ,再从最小正整数1开始依次校验,找到第一个不在哈希表中的正整数,就是答案。