class Solution {
public boolean isValid(String s) {
char[] chars = s.toCharArray();
Stack<Character> Stack1 = new Stack();
for(Character c:chars){
if(c=='('||c=='['||c=='{'){
Stack1.add(c);
}else{
if(Stack1.isEmpty()){
return false;
}
char peek = Stack1.pop();
if(c==')'&&peek!='('||c=='}'&&peek!='{'||c==']'&&peek!='['){
return false;
}
}
}
return Stack1.isEmpty();
}
}
01-11
435
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-07
242
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-12
1355
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)