問題描述
我的第一個解決方案:
/** * @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中文網其他相關文章!