Title: #20 - Valid Parentheses - LeetCode JavaScript Solutions
Open Graph Title: #20 - Valid Parentheses - LeetCode JavaScript Solutions
X Title: #20 - Valid Parentheses - LeetCode JavaScript Solutions
Description: Given a string s containing just the characters '(', ')', '{', '}', '[' and ']',...
Open Graph Description: Given a string s containing just the characters '(', ')', '{', '}', '[' and ']',...
X Description: Given a string s containing just the characters '(', ')', '{', '}', '[' and ']',...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/valid-parentheses
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/valid-parentheses","name":"#20 - Valid Parentheses - LeetCode JavaScript Solutions","description":"Given a string s containing just the characters '(', ')', '{', '}', '[' and ']',...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {string} s\n * @return {boolean}\n */\nvar isValid = function(s) {\n const map = {\n '(': ')',\n '[': ']',\n '{': '}',\n };\n const stack = [];\n\n for (let i = 0; i < s.length; i++) {\n if (map[s[i]]) {\n stack.push(map[s[i]]);\n } else {\n if (stack.pop() !== s[i]) {\n return false;\n }\n }\n }\n\n return stack.length === 0;\n};","keywords":"LeetCode 20, #20 - Valid Parentheses, Easy, 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/valid-parentheses |
| 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/valid-parentheses/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0020-valid-parentheses.js |
| String | https://leetcodejavascript.com/tags/string |
| Stack | https://leetcodejavascript.com/tags/stack |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow