Skip to content

Commit 550f25e

Browse files
add 1859
1 parent 5aa354b commit 550f25e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1859|[Sorting the Sentence](https://leetcode.com/problems/sorting-the-sentence/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1859.java) ||Easy|String, Sort|
1112
|1854|[Maximum Population Year](https://leetcode.com/problems/maximum-population-year/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1854.java) ||Easy|Array|
1213
|1848|[Minimum Distance to the Target Element](https://leetcode.com/problems/minimum-distance-to-the-target-element/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1848.java) ||Easy|Array|
1314
|1845|[Seat Reservation Manager](https://leetcode.com/problems/seat-reservation-manager/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1845.java) ||Medium|Heap, Design|
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.TreeMap;
4+
5+
public class _1859 {
6+
public static class Solution1 {
7+
public String sortSentence(String s) {
8+
String[] words = s.split(" ");
9+
TreeMap<Integer, String> treeMap = new TreeMap<>();
10+
for (String word : words) {
11+
int key = Integer.parseInt(word.charAt(word.length() - 1) + "");
12+
treeMap.put(key, word.substring(0, word.length() - 1));
13+
}
14+
StringBuilder sb = new StringBuilder();
15+
for (int key : treeMap.keySet()) {
16+
sb.append(treeMap.get(key));
17+
sb.append(" ");
18+
}
19+
return sb.substring(0, sb.length() - 1);
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy