filmov
tv
How I solved LeetCode 20. Valid Parentheses in JavaScript

Показать описание
Hey! My name is Tomas. Thanks for checking out my channel.
Problem
LeetCode 20. Valid Parentheses
GitHub Solution
Resources
Notes
• if there is an odd number of brackets, return false; Because in order to have valid parentheses we need to have even number parens
• we want to create a map, to keep track of our parentheses
let map = {
')':'(',
'}':'{',
']':'['
}
• we want to keep a stack to keep track of our open parens
• for loop, to iterate through the array
• variable to keep track of our character
conditional
• if the character is an opening paren and not a closing paren, we add it to the stack
• if the current character is a closing bracket and it's value ( the matching opening bracket )is the last character, pop it off the stack
• if it is not the matching character, return false;
at the very end, return whether or not we've been left with any opening brackets in the stack
Connect with me on GitHub: R-Tomas-Gonzalez (Tomas Gonzalez)
Happy Coding!
#codinginterview #leetcode #algorithms #javascript #validparentheses #datastructures #blind75 #jobsearch #coding
Problem
LeetCode 20. Valid Parentheses
GitHub Solution
Resources
Notes
• if there is an odd number of brackets, return false; Because in order to have valid parentheses we need to have even number parens
• we want to create a map, to keep track of our parentheses
let map = {
')':'(',
'}':'{',
']':'['
}
• we want to keep a stack to keep track of our open parens
• for loop, to iterate through the array
• variable to keep track of our character
conditional
• if the character is an opening paren and not a closing paren, we add it to the stack
• if the current character is a closing bracket and it's value ( the matching opening bracket )is the last character, pop it off the stack
• if it is not the matching character, return false;
at the very end, return whether or not we've been left with any opening brackets in the stack
Connect with me on GitHub: R-Tomas-Gonzalez (Tomas Gonzalez)
Happy Coding!
#codinginterview #leetcode #algorithms #javascript #validparentheses #datastructures #blind75 #jobsearch #coding