MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / sortSentence

Method sortSentence

SortingTheSentence.java:2–18  ·  view source on GitHub ↗
(String s)

Source from the content-addressed store, hash-verified

1class Solution {
2 public String sortSentence(String s) {
3 String arr[] = s.split(" ");
4 String temp[] = new String[arr.length];
5 String res="";
6
7 for(int i=0;i<arr.length;i++)
8 {
9 int index = arr[i].charAt(arr[i].length()-1)-'0';
10 temp[index-1] = arr[i].substring(0,arr[i].length()-1);
11 }
12 for(int i=0;i<temp.length;i++)
13 {
14 res+=temp[i];
15 res+=" ";
16 }
17 return res.trim();
18 }
19}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected