题解 | #栈的压入、弹出序列#
栈的压入、弹出序列
https://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106
function IsPopOrder(pushV, popV) { // write code here //借助辅助栈 let stack = []; let i = 0; let j = 0; while(i < pushV.length){ stack.push(pushV[i]); // 如果stack 和 出栈顺序popV中的元素一直一样,则一直循环下去 一直执行pop操作 while(stack[stack.length-1] == popV[j] && i < pushV.length && j < popV.length){ stack.pop(); j += 1; } i += 1; } while(stack.length > 0){ if(stack[stack.length-1] != popV[j]){ return false; } stack.pop() } return true; } module.exports = { IsPopOrder : IsPopOrder };#我的实习求职记录#