题解 | #栈的压入、弹出序列#,建一个辅助栈,即可
栈的压入、弹出序列
https://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106?tpId=308&tqId=2111163&ru=%2Fexam%2Fcompany&qru=%2Fta%2Falgorithm-start%2Fquestion-ranking&sourceUrl=%2Fexam%2Fcompany
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param pushV int整型一维数组 * @param popV int整型一维数组 * @return bool布尔型 */ function IsPopOrder( pushV , popV ) { // write code here let arr = []; let len = pushV.length; let popCount = 0; for(let i = 0;i<len;i++){ arr.push(pushV[i]); while(popV[popCount]!==undefined&&arr[arr.length-1]===popV[popCount]){ arr.pop(); popCount++; } } return !arr.length } module.exports = { IsPopOrder : IsPopOrder };