Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @param {number[]} pushed
- * @param {number[]} popped
- * @return {boolean}
- */
- var validateStackSequences = function(pushed, popped) {
- let arr = [];
- let j = 0;
- for(let i = 0; i < pushed.length; i++) {
- arr.push(pushed[i])
- if(arr[arr.length - 1] === popped[j]) {
- while(arr.length && arr[arr.length - 1] === popped[j]) {
- arr.pop();
- j++;
- }
- }
- }
- return arr.length === 0
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement