https://school.programmers.co.kr/learn/courses/30/lessons/76502
const solution = (s) => {
const obj = {
"[": "]",
"(": ")",
"{": "}",
};
return [...s].reduce((acc, el, idx) => {
const stack = [];
for (let i = 0; i < s.length; ++i) {
const a = (idx + i) % s.length;
if (Object.keys(obj).find((key) => key === s[a])) stack.push(s[a]);
else if (Object.values(obj).find((value) => value === s[a])
&& obj[stack[stack.length - 1]] === s[a]) stack.pop();
else return acc;
}
return (stack.length ? acc : ++acc);
}, 0);
};
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (해시) Lv 2. 의상 (0) | 2023.02.07 |
---|---|
[Programmers] Lv 2. 행렬의 곱셈 (0) | 2023.02.07 |
[Programmers] (2018 KAKAO BLIND RECRUITMENT) Lv 2. [1차] 캐시 (0) | 2023.02.04 |
[Programmers] (정렬) Lv 2. H-Index (0) | 2023.02.04 |
[Programmers] (Summer/Winter Coding(~2018)) Lv 2. 점프와 순간 이동 (0) | 2023.02.03 |
댓글