题解 | #序列找数#

序列找数

http://www.nowcoder.com/practice/a7d1856a72404ea69fdfb5786d65539c

import java.util.*;
public class Main{
    public static void main(String[] args) {
        setTest();
    }
    public static void setTest() {
        Set<Integer> tmpSet = new HashSet<>();
        Set<Integer> collect = new HashSet<>();
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i <= n; i++) {
            collect.add(i);
        }
        for (int i = 0; i < n; i++) {
            int item = scanner.nextInt();
            tmpSet.add(item);
        }

        collect.removeAll(tmpSet);
        collect.stream().forEach(System.out::println);
    }
}
全部评论

相关推荐

评论
1
1
分享

创作者周榜

更多
牛客网
牛客企业服务