You are viewing a single comment's thread. Return to all comments →
Java Solution:
public static List<Integer> countingSort(List<Integer> arr) { Map<Integer, Integer> countMap = new HashMap<>(); for(int i=0; i< arr.size(); i++){ int current = arr.get(i); if(countMap.containsKey(current)){ int count = countMap.get(current); countMap.put(current, count+1); }else{ countMap.put(current, 1); } } List<Integer> list = new ArrayList<>(100); for(int i=0; i<100; i++){ if(countMap.containsKey((i))){ list.add(countMap.get(i)); }else{ list.add(0); } } return list; }
Seems like cookies are disabled on this browser, please enable them to open this website
Counting Sort 1
You are viewing a single comment's thread. Return to all comments →
Java Solution: