Back to Browse

How I solved LeetCode 20. Valid Parentheses in JavaScript

26 views
Sep 22, 2023
8:48

Hey! My name is Tomas. Thanks for checking out my channel. Problem LeetCode 20. Valid Parentheses https://leetcode.com/problems/valid-parentheses/ GitHub Solution Solution: https://github.com/R-Tomas-Gonzalez/github/tree/main/0020-valid-parentheses Resources Stack: https://www.geeksforgeeks.org/stack-data-structure/ Modulo: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder 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 LinkedIn: https://www.linkedin.com/in/rtomasgonzalez/ Connect with me on GitHub: R-Tomas-Gonzalez (Tomas Gonzalez) Happy Coding! #codinginterview #leetcode #algorithms #javascript #validparentheses #datastructures #blind75 #jobsearch #coding

Download

0 formats

No download links available.

How I solved LeetCode 20. Valid Parentheses in JavaScript | NatokHD