题解 | #序列找数#
序列找数
https://www.nowcoder.com/practice/a7d1856a72404ea69fdfb5786d65539c
import java.util.Scanner;
import java.util.HashSet;
import java.util.Set;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Set<Integer> set=new HashSet<>();
int count=0;
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
set.add(in.nextInt());
count++;
}
for(int i=0;i<count;i++){
if(!set.contains(i)){
System.out.println(i);
}
}
//System.out.println(count);
}
}
利用hashset去重放入,遍历0-n,没有的输出