编辑代码

import java.util.Arrays;

class Main {
    public static void countSort(int[] arrays) {

        if (arrays == null)
            return;

        int min = Arrays.stream(arrays).min().getAsInt();
        int max = Arrays.stream(arrays).max().getAsInt();

        int[] arr = new int[max - min + 1];
        int offset = min;
        for (int i : arrays) {
            arr[i - offset]++;
        }

        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != 0) {
                for (int j = 0; j < arr[i]; j++)
                    System.out.print(offset + i + " ");
            }
        }
        System.out.println();
    }

    public static void main(String[] args) {
        int[] arr = {3, 1, 6, 7, 2, 5, 1, 7};
        countSort(arr);

        int[] arr1 = {99, 91, 90, 35, 50, 31, 92, 97, 78, 100};
        countSort(arr1);
    }
}