public static String reverseWords(String s) {
String [] revStr = s.split(" ");
StringBuilder res =new StringBuilder();
for (int i = revStr.length-1; i >=0 ; i--) {
if(!revStr[i].equals("")){
res.append(revStr[i]+" ");
}
}
return res.toString().trim();
}
leet151:翻转字符串
最新推荐文章于 2023-01-03 14:22:41 发布