/**
* @author xnl
* @Description:
* @date: 2022/6/14 22:36
*/
public class Solution {
public static void main(String[] args) {
Solution solution = new Solution();
String s = "is2 sentence4 This1 a3";
System.out.println(solution.sortSentence(s));
}
public String sortSentence(String s) {
String[] split = s.split("\\s+");
String[] ans = new String[split.length];
for (String str : split) {
int index = str.charAt(str.length() - 1) - '0';
ans[index - 1]= str.substring(0, str.length() - 1);
}
return String.join(" ", ans);
}
}
力扣:1859. 将句子排序
最新推荐文章于 2024-08-15 05:02:54 发布