import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
Set<Integer> l = new HashSet<Integer>();
for(int i = 0; i < n; i++){
int tmp = in.nextInt();
l.add(tmp);
}
for(int i = 0; i <= n; i++){
if(!l.contains(i)){
System.out.println(i);;
break;
}
}
// 注意 hasNext 和 hasNextLine 的区别
// while (in.hasNextInt()) { // 注意 while 处理多个 case
// int a = in.nextInt();
// int b = in.nextInt();
// System.out.println(a + b);
// }
}
}
使用集合(线性表也行),依次找0~N的所有数,判断是否出现在集合中

京公网安备 11010502036488号