We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f4c3051 commit 2babe9bCopy full SHA for 2babe9b
Easy/Sorting the Sentence.java
@@ -0,0 +1,21 @@
1
+class Solution {
2
+ public String sortSentence(String s) {
3
+ String[] arr = new String[s.split(" ").length];
4
+ int idx = 0;
5
+ int n = s.length();
6
+ while (idx < n) {
7
+ int currIdx = idx;
8
+ while (currIdx < n && Character.isLetter(s.charAt(currIdx))) {
9
+ currIdx++;
10
+ }
11
+ int wordIdx = Character.getNumericValue(s.charAt(currIdx++));
12
+ arr[wordIdx - 1] = s.substring(idx, currIdx - 1);
13
+ idx = currIdx + 1;
14
15
+ StringBuilder sb = new StringBuilder();
16
+ for (String word : arr) {
17
+ sb.append(word).append(" ");
18
19
+ return sb.toString().trim();
20
21
+}
0 commit comments