题解 | #明明的随机数#
明明的随机数
http://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
朴素的方法,代码反而更难
import java.util.*; public class Main{ public static void main(String[] args){ Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ int N = scanner.nextInt(); List<Integer> list = new ArrayList<>(N); for (int i = 0; i < N; i++) { int var = scanner.nextInt(); if(!list.contains(var)){ list.add(var); } } list.sort(new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o1.compareTo(o2); } }); Object[] objects = list.toArray(); for(Object object : objects){ System.out.println(object); } } } }