20. Valid Parentheses
Given a string containing just the characters'('
,')'
,'{'
,'}'
,'['
and']'
, determine if the input string is valid.
The brackets must close in the correct order,"()"
and"()[]{}"
are all valid but"(]"
and"([)]"
are not.
Thoughts:
Use the map to map each parentheses corresponding, Use a stack (either implemented as vector or stack) to keep track of current parentheses state.
Python
Last updated
Was this helpful?