@@ -0,0 +1,735 @@
+package leetcode;%0A%0Aimport java.util.Arrays;%0A%0A/**%0A * https://leetcode.com/problems/sorting-the-sentence/%0A */%0Apublic class Problem1859 %7B%0A    public String sortSentence(String s) %7B%0A        String%5B%5D words = s.split(%22 %22);%0A        Arrays.sort(words, (a, b) -%3E %7B%0A            int index1 = a.charAt(a.length() - 1) - '0';%0A            int index2 = b.charAt(b.length() - 1) - '0';%0A            return Integer.compare(index1, index2);%0A        %7D);%0A        StringBuilder answer = new StringBuilder();%0A        for (int i = 0; i %3C words.length; i++) %7B%0A            if (i %3E 0) %7B%0A                answer.append(%22 %22);%0A            %7D%0A            answer.append(words%5Bi%5D.substring(0, words%5Bi%5D.length() - 1));%0A        %7D%0A        return answer.toString();%0A    %7D%0A%7D%0A

Solve problem 1859