一、题目地址
https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/
二、具体代码
/**
* @param {number[]} pushed
* @param {number[]} popped
* @return {boolean}
*/
// 辅助栈
// 时间复杂度:O(N)
// 空间复杂度:O(N)
var validateStackSequences = function(pushed, popped) {
let stack = [];
let i = 0;
for(let num of pushed) {
stack.push(num);
while((stack.length !== 0) && (stack[stack.length - 1] === popped[i])) {
stack.pop();
i++;
}
}
return stack.length === 0;
};
三、补充链接
https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/solution/mian-shi-ti-31-zhan-de-ya-ru-dan-chu-xu-lie-mo-n-2/