/**
* @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. 将句子排序
最新推荐文章于 2025-12-04 23:36:16 发布
本文介绍了如何使用Java实现一个Solution类,通过sortSentence方法对输入的字符串进行排序,将数字字符转换为相应位置的字母。主要展示了字符串处理和数组操作的技巧。
503

被折叠的 条评论
为什么被折叠?



