题解 | #序列找数#
序列找数
https://www.nowcoder.com/practice/a7d1856a72404ea69fdfb5786d65539c
import java.util.Scanner;
import java.util.Arrays;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
int n = in.nextInt();
int[] nums = new int[n + 1];
// 使用数组作为哈希表
for (int i = 0; i < n; i++) {
int cur = in.nextInt();
nums[cur] = 1;
}
// 判断缺少哪个数字
for (int j = 0; j < n + 1; j++) {
if (nums[j] != 1) {
System.out.print(j);
return;
}
}
in.close();
}
}

