class Solution {
String left = "({[";
public boolean isValid(String s) {
Stack mStack = new Stack<>();
HashMap<String, String> hashMap = new HashMap(){};
hashMap.put(")", "(");
hashMap.put("]", "[");
hashMap.put("}", "{");
for (int i = 0; i < s.length(); i++) {
String one = s.substring(i, i + 1);
if (hashMap.containsValue(one)){
//左括号
mStack.push(one);
}else {
if (mStack.isEmpty()||!((String) mStack.pop()).equals(hashMap.get(one))) {
return false;
}
}
}
return mStack.isEmpty();
}
}
https://leetcode-cn.com/problems/valid-parentheses/