0020 Valid Parentheses
Warning
This post is more than a year old. Information may be outdated.
Solved at: 220710
Question
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
- Open brackets must be closed by the same type of brackets.
- Open brackets must be closed in the correct order.
Solution
This is a classic stack problem.
I missed some details:
- Remember
pop()doesn't take any argument. - Remember to check the final condition. When the list is not empty at the end, then return
False.
Comments