이번 글에서는 LeetCode에서 Valid Parentheses 문제를 풀어보겠다
function isValid(s: string): boolean { let stack = []; const pairBrackets = new Map(); pairBrackets.set("(",")"); pairBrackets.set("{","}"); pairBrackets.set("[","]"); for(const x of s) { if(pairBrackets.has(x)) { stack.push(x); } else { const lastOne = stack.pop(); if(pairBrackets.get(lastOne) !== x) return false; } } return stack.length === 0; };