题解 | #序列找数#
序列找数
https://www.nowcoder.com/practice/a7d1856a72404ea69fdfb5786d65539c
//哈希表实现 import java.util.Scanner; 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(); HashSet<Integer> res = new HashSet<Integer>(); // 注意 hasNext 和 hasNextLine 的区别 for (int i = 0; i < n; i++) { res.add(in.nextInt()); } for (int i = 0 ; i < n; i++) { if (!res.contains(i)) { System.out.println(i); break; } } } }