题解 | #栈的压入、弹出序列#
function IsPopOrder(pushV, popV)
{
// write code here
//模拟整个压栈和出栈过程就可以了
//创建一个栈用于模拟
let stack = []
let j = 0
for (let i = 0; i < pushV.length; i++){
stack.push(pushV[i])
while(stack.length !== 0 && stack[stack.length - 1] == popV[j]){
j++
stack.pop()
}
}
if(stack.length == 0) {
return true
}else {
return false
}
}
module.exports = {
IsPopOrder : IsPopOrder
};