题解 | #序列中整数去重#

序列中整数去重

http://www.nowcoder.com/practice/6564a2f6e70f4153ad1ffd58b2b28490

题解:使用LinkeHashSet可以保持原来顺序,又可以去重

import java.util.*;
public class Main{
    public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            int[] a = new int[n];
           for(int i = 0; i < n; i++){
               a[i] = sc.nextInt();
            }
             sort(a);
        } 
    }
    
    public static void sort(int[] a){
    Set<Integer> set = new LinkedHashSet<>();
         for(int j = 0; j < a.length; j++){
             set.add(a[j]);
            }
        for(Integer i : set){
             System.out.print(i + " ");
        }
    }
}
全部评论

相关推荐

码农索隆:单休一个月少休息4天,一年就是48天,平时节假日,别人3天假期,单休的两天
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-09 12:02
ssob上原来真有BOSS啊
硫蛋蛋:这种也是打工的,只不是是给写字楼房东打工
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务