题解 | #明明的随机数#
明明的随机数
https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { HashSet<Integer> set = new HashSet<>(); Scanner in = new Scanner(System.in); int N = in.nextInt(); int[] arr = new int[N]; for(int i = 0;i < N;++i){ arr[i] = in.nextInt(); } for(int num : arr){ Integer i = new Integer(num); set.add(i); } int[] array = new int[set.size()]; int index = 0; for(Integer n : set){ array[index++] = n.intValue(); } quickSort(array,0,array.length-1); for(int i = 0;i<array.length;++i){ System.out.println(array[i]); } } public static void quickSort(int[] arrs, int start, int end){ int low = start,high = end; if(start < end){ int guard = arrs[start]; while (low != high){ while(low < high && arrs[high] >= guard){ high--; } while(low < high && arrs[low] <= guard){ low++; } if(low < high){ int temp = arrs[low]; arrs[low] = arrs[high]; arrs[high] = temp; } } arrs[start] = arrs[low]; arrs[low] = guard; quickSort(arrs,start,low-1); quickSort(arrs,low+1,end); } } }