题解 | #明明的随机数#
明明的随机数
https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
使用java8中StreanAPI处理很方便,Stream可以有去重distinct
import java.io.IOException; import java.util.Arrays; import java.util.Scanner; import java.util.stream.IntStream; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()){ int inNum = sc.nextInt(); int[] count = new int[inNum]; for (int i = 0; i <inNum; i++) { count[i] = sc.nextInt(); } IntStream stream = Arrays.stream(count); stream.distinct().sorted().forEach(System.out::println); } } }