LeetCode 20.

Tags:

Today for Freeday Friday I did not feel like doing the Pacman project, so I decided to solve a LeetCode problem. I went for an easy one because I did not wanna twist my gears too hard. This LeetCode problem has to deal with parentheses. I have to make sure that certain parentheses are in their correct order and everything is in line. Here is the exact problem:

At first I thought that I could simply do multiple if statements to see if they are in their correct spot but then I realized that is not very practical. If I were to go with that Idea, the parentheses would have to be In a VERY specific order, it would have to look like ‘()[]{}’ and it could not look like ‘[]{}()’ even though both are correct. So, what I decided to do was make a stack and check if the parentheses match and go down the list until all of them are where they need to be. This is the finished product code:

This was a very informative LeetCode activity, I see myself doing more in the future, if someone is thinking of learning code I think LeetCode is a great thing to get into.

Categories

No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *