20_Valid Parentheses
[easy] [string, stack]
Given a string containing just the characters'('
,')'
,'{'
,'}'
,'['
and']'
, determine if the input string is valid.
The brackets must close in the correct order.
Example:
Example:
Example:
Solution: using stack
The rule is when right parentheses comes, it must be matched with the closest left parentheses on the left with the same type.
So we need to use stack to store all the left parentheses that have not been paired.
Last updated