题解 | #明明的随机数#
明明的随机数
http://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
//题目要去重排序 //数据结构想到TreeSet, Tree有序的,set去重 import java.util.*; public class Main{ public static void main(String[] args){ Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ int num =scanner.nextInt(); //创建TreeSet进行去重排序 TreeSet set = new TreeSet(); for(int i =0 ; i < num ;i++){ set.add(scanner.nextInt()); } //遍历TreeSet,输出 Iterator iterator = set.iterator(); while(iterator.hasNext()){ System.out.println(iterator.next()); } } } }