Counting Sort 1

  • + 1 comment

    Easy Java solution:

    public static List<Integer> countingSort(List<Integer> arr) {
        //creates list with 100 elements filled with zeros
        List<Integer> res = new ArrayList<Integer>(Collections.nCopies(100, 0));
        for(Integer a : arr)
                res.set(a, res.get(a)+1);
        return res;
    }