Skip to content

Commit a419d52

Browse files
committed
99차 3번 문제풀이
1 parent 7893904 commit a419d52

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

live9/test99/문제3/조진우.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function solution(s) {
2+
const isValid = (str) => {
3+
const stack = [];
4+
const pairs = {
5+
")": "(",
6+
"]": "[",
7+
"}": "{",
8+
};
9+
10+
for (const char of str) {
11+
if (char === "(" || char === "[" || char === "{") {
12+
stack.push(char);
13+
} else {
14+
if (stack.pop() !== pairs[char]) return false;
15+
}
16+
}
17+
18+
return stack.length === 0;
19+
};
20+
21+
let count = 0;
22+
for (let i = 0; i < s.length; i++) {
23+
const rotated = s.slice(i) + s.slice(0, i);
24+
if (isValid(rotated)) count++;
25+
}
26+
27+
return count;
28+
}
29+
30+
console.log(solution("[](){}"));

0 commit comments

Comments
 (0)