import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @return bool布尔型
*/
public boolean equalReverse(char s1, char s2) {
return s1 == '[' && s2 == ']'
|| s1 == '{' && s2 == '}'
|| s1 == '(' && s2 == ')';
}
public boolean isValid (String s) {
Stack<Character> st = new Stack<>();
for (int i=0;i<s.length();++i) {
char c = s.charAt(i);
if (st.empty()) {
st.push(c);
} else {
if (equalReverse(st.peek(), c)){
st.pop();
}else{
st.push(c);
}
}
}
return st.empty();
}
}