Leetcode in Java && Oracle
422 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2021-11-07_04-26-24.png
44 KB
#N1859. Sorting the Sentence
problem link

#solution
class Solution {
public String sortSentence(String s) {
String[] words=s.split(" ");
String[] sorted=new String[words.length];
String res="";

for(String word:words){
sorted[Character.getNumericValue(word.charAt(word.length()-1))-1]=word.substring(0, word.length()-1);
}

for(int i=0; i<sorted.length; i++){
res+=sorted[i];
if(i!=sorted.length-1)
res+=" ";
}

return res;
}
}