问题描述
我的第一个解决方案:
/** * @param {string} s * @return {boolean} */ var isValid = function (s) { let stack = []; let compliments = { ")": "(", "]": "[", "}": "{" }; for (let char of s) { if (char === "(" || char === "[" || char === "{") { stack.push(char); } else if (stack.length === 0 || stack.pop() !== compliments[char]) { return false; } } return stack.length === 0; };
以上是有效括号的详细内容。更多信息请关注PHP中文网其他相关文章!