LeetCode 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.
思路
看到这种括弧匹配问题,我首先想到的就是用stack来实现。
代码
|
|
C语言版本: