利用TreeSet的有序性、无重复性

小乐乐与序列

http://www.nowcoder.com/questionTerminal/9a1c1c764ce04fed8ceff7714e74d3b6

利用TreeSet的有序性、无重复性:

import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Set<Integer> v = new TreeSet<>();
        int n = sc.nextInt();
        while (sc.hasNext()) v.add(sc.nextInt());
        for(Integer i : v) System.out.printf("%d ", i);
    }
}
全部评论

相关推荐

点赞 评论 收藏
转发
1 收藏 评论
分享
牛客网
牛客企业服务