https://leetcode.cn/problems/valid-parentheses/
class Solution {
public boolean isValid(String string) {
Stack<Character> stack = new Stack<>();
for (int i = 0, len = string.length(); i < len; i++) {
char char1 = string.charAt(i);
if (!stack.isEmpty() && check(char1, stack.peek())) {
stack.pop();
}
else {
stack.push(char1);
}
}
return stack.isEmpty();
}
public static boolean check(char pre, char peek) {
String add = String.valueOf(peek) + String.valueOf(pre);
if ("[]".equals(add) || "{}".equals(add) || "()".equals(add)) {
return true;
}
return false;
}
}