题解 | #明明的随机数#
明明的随机数
http://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
主要是集合的判断元素和排序,还有就是addAll方法
import java.util.*; public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); ArrayList<Integer> list= new ArrayList<Integer>(); ArrayList<Integer> result = new ArrayList<Integer>(); while (in.hasNextInt()){ int n = in.nextInt(); for (int i = 0 ;i< n;i++){ int v = in.nextInt(); if (!list.contains(v)) { list.add(v); } } list.sort(new Comparator<Integer>(){ @Override public int compare(Integer arg0 , Integer arg1 ) { return arg0.compareTo(arg1); //这是顺序 } }); result.addAll(list); list.clear(); } for(Integer v :result){ System.out.println(v); } } }