0020 Valid Parentheses
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.
Results
Runtime
- 67 ms, faster than 11.18% of Python3 online submissions for Valid Parentheses.
Memory Usage
- 13.9 MB, less than 24.23% of Python3 online submissions for Valid Parentheses.
Other Answers Online
- All of the other solutions I found had similar approaches.
- This is funny.
Backlinks (2)
Comments (0)