题目链接
思路
最起码能看出来这是要用到栈
思路我明天再写
代码
class Solution {
public boolean isValid(String s) {
Stack<Character> stack=new Stack();
for(int i=0;i<s.length();i++){
char c = s.charAt(i);
if(c=='(')stack.push(')');
else if(c=='[')stack.push(']');
else if(c=='{')stack.push('}');
else if(stack.isEmpty() || stack.pop()!=c)
return false;
}
return stack.isEmpty();
}
}