思路: 入栈后在出栈 顺序就会发生变化

import java.util.*;
public class Solution {
    public String ReverseSentence(String str) {
        Stack<String> stack=new Stack<>();
        String[] temp=str.split(" ");
        //入栈
        for(int i=0;i<temp.length;i++){
        stack.push(temp[i]);
        stack.push(" ");
        }
         StringBuilder res = new StringBuilder();
        if(!stack.isEmpty()){
            //取出顶部空格
            stack.pop();
        }
         while(!stack.isEmpty()){
            res.append(stack.pop());
         }
         return res.toString();
    }
}