输入:s = “(]”
输出:false
class Solution {
public boolean isValid(String s) {
//栈
Stack<Character> stack = new Stack();
int len = s.length();
for(char c:s.toCharArray())
{
//为左边的就加入右边的
if(c == '(')
stack.push(')');
else if(c == '{')
stack.push('}');
else if(c == '[')
stack.push(']');
else
//栈为空或不匹配就false
if(stack.empty() || stack.pop()!=c)
return false;
}
return stack.empty();
}
}