题解 | #翻转单词序列#
翻转单词序列
http://www.nowcoder.com/practice/3194a4f4cf814f63919d0790578d51f3
import java.util.*;
public class Solution {
public String ReverseSentence(String str) {
String[] ss = str.split(" ");
Stack<String> st = new Stack<>();
StringBuilder sb = new StringBuilder();
for(String s : ss){
st.push(s);
}
while(!st.isEmpty()){
sb.append(st.pop());
sb.append(" ");
}
sb.deleteCharAt(sb.length() - 1);
return sb.toString();
}
}