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.
思路:
1. 利用堆栈的性质,为空则压入新值,依次检查字符串中字符与堆栈顶端是否匹配。
2. 匹配则弹出堆栈顶部值,同时不压入新值。
3. 对于所有右键的情况,直接压入。
No comments:
Post a Comment