- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1859.java
22 lines (20 loc) · 757 Bytes
/
_1859.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
packagecom.fishercoder.solutions.secondthousand;
importjava.util.TreeMap;
publicclass_1859 {
publicstaticclassSolution1 {
publicStringsortSentence(Strings) {
String[] words = s.split(" ");
TreeMap<Integer, String> treeMap = newTreeMap<>();
for (Stringword : words) {
intkey = Integer.parseInt(word.charAt(word.length() - 1) + "");
treeMap.put(key, word.substring(0, word.length() - 1));
}
StringBuildersb = newStringBuilder();
for (intkey : treeMap.keySet()) {
sb.append(treeMap.get(key));
sb.append(" ");
}
returnsb.substring(0, sb.length() - 1);
}
}
}