We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
A Java solution (works in Java 15 because in Java 8 Testcase 5 has timeout error):
publicstaticvoidcountSort(List<List<String>>arr){// change the first half of the strings to "-"for(inti=0;i<arr.size()/2;i++){List<String>tempList=arr.get(i);tempList.set(1,"-");arr.set(i,tempList);}// order the listarr.sort(Comparator.comparingInt(s->Integer.parseInt(s.get(0))));// make a stringJoinerStringJoinerstringJoiner=newStringJoiner(" ");for(List<String>element:arr){stringJoiner.add(element.get(1));}System.out.println(stringJoiner);}
The Full Counting Sort
You are viewing a single comment's thread. Return to all comments →
A Java solution (works in Java 15 because in Java 8 Testcase 5 has timeout error):