Valid Parentheses

Sean Ransonette
2 min readNov 24, 2021

Today I will be writing about another algorithm that I worked on recently for algorithm practice. In this case it is Valid Parentheses.

The concept is basically, given a string of characters like( , { , [ , the correct closing character must be used. () {} [] like this.

To start this I made a reference object to compare the bracket types to.

Once we have this object we need to iterate through the string provided and store characters we iterate though into a new array so we can compare the next order in the iteration like so

Finally we need the if statements comparing the characters in the array.

The if statements basically read as, if bracket character is true as in it matches push that character into the array. Else, check if the last character in the array does not match the necessary character then return false.

--

--