剑指 offer 58-01 翻转单词顺序
分割+倒序
class Solution {
public String reverseWords(String s) {
s.trim();//删除首尾空格
String[] strs = s.split(" ");
StringBuilder sb = new StringBuilder();
for (int i=strs.length-1;i>=0;i--){
if(!strs[i].equals(""))
sb.append(strs[i]+" ");
}
return sb.toString().trim();
}
}