题解 | #翻转单词序列#
翻转单词序列
http://www.nowcoder.com/practice/3194a4f4cf814f63919d0790578d51f3
function ReverseSentence(str) { // write code here if (str ==="") return ""; let arr = str.split(" "); let result =[] let stack = []; for (let i=0;i<arr.length;i++){ stack.push(arr[i]); } while (stack.length !==0){ result.push(stack.pop()); } return result.join(" ") } module.exports = { ReverseSentence : ReverseSentence };