括号匹配度判断
括号匹配度判断
function isMatch(str) { let stack = new Stack(); for (let i = 0; i < str.length; i++) { if (str[i] == "(" || str[i] == "[" || str[i] == "{") { stack.push(str[i]);//进栈 } else { switch (str[i]) { case ")": if (stack.pop() != "(") { return false; break; } break; case "}": if (stack.pop() != "{") { return false; break; } break; case "]": if (stack.pop() != "[") { return false; break; } break; } } } if(stack.isEmpty()){ return true }else{ return false } } console.log(isMatch("[{()}]")); console.log(isMatch("[({}))}]"));