Muscardinus
괄호 회전하기 본문
728x90
https://programmers.co.kr/learn/courses/30/lessons/76502
function solution(s) {
let answer = 0;
const check = (str) => {
const s = str.split("");
const q = [];
const cnt = 0;
for (let i = 0; i < s.length; i++) {
if (['[', '(', '{'].includes(s[i])) {
q.push(s[i]);
} else {
if (!q.length) return false;
const c = q.pop();
if (c === '(' && s[i] !== ')') return false;
if (c === '[' && s[i] !== ']') return false;
if (c === '{' && s[i] !== '}') return false;
}
}
if (q.length) return false;
return true;
}
for (let i = 0; i < s.length; i++) {
const prev = s.slice(i);
const next = s.slice(0, i);
if (check(prev + next)) answer++;
}
return answer;
}
728x90
Comments