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.
思路:这道题可以用栈来做。比如"("、“["、"{"表示压栈的操作,另外三个字符表示出栈的操作。当来一个出栈的字符,将栈顶元素出栈,看其是否匹配,不匹配则false,匹配则继续,直到string到尾部并且栈为空。
class Solution {
public:
bool isPush(char a)
{
if (a......
阅读全文