Title: #946 - Validate Stack Sequences - LeetCode JavaScript Solutions
Open Graph Title: #946 - Validate Stack Sequences - LeetCode JavaScript Solutions
X Title: #946 - Validate Stack Sequences - LeetCode JavaScript Solutions
Description: Given two integer arrays pushed and popped each with distinct values, return true if this could have been the result of a sequence of push a...
Open Graph Description: Given two integer arrays pushed and popped each with distinct values, return true if this could have been the result of a sequence of push a...
X Description: Given two integer arrays pushed and popped each with distinct values, return true if this could have been the result of a sequence of push a...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/validate-stack-sequences
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/validate-stack-sequences","name":"#946 - Validate Stack Sequences - LeetCode JavaScript Solutions","description":"Given two integer arrays pushed and popped each with distinct values, return true if this could have been the result of a sequence of push a...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number[]} pushed\n * @param {number[]} popped\n * @return {boolean}\n */\nvar validateStackSequences = function(pushed, popped) {\n const stack = [];\n let popIndex = 0;\n\n for (const number of pushed) {\n stack.push(number);\n\n while (stack.length && stack[stack.length - 1] === popped[popIndex]) {\n stack.pop();\n popIndex++;\n }\n }\n\n return stack.length === 0;\n};","keywords":"LeetCode 946, #946 - Validate Stack Sequences, Medium, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/validate-stack-sequences |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/validate-stack-sequences/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0946-validate-stack-sequences.js |
| Array | https://leetcodejavascript.com/tags/array |
| Simulation | https://leetcodejavascript.com/tags/simulation |
| Stack | https://leetcodejavascript.com/tags/stack |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width,initial-scale=1
Robots: index, follow