Skip to content

Commit d443cd1

Browse files
author
Eric
committed
99차 3번 문제풀이
1 parent a46e6e6 commit d443cd1

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

live9/test99/문제3/황장현.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function solution(s) {
2+
const obj = {
3+
'}': '{',
4+
']': '[',
5+
')': '(',
6+
};
7+
8+
const isCorrect = (string) => {
9+
const stack = [];
10+
for (const char of string) {
11+
if ('{[('.includes(char)) stack.push(char);
12+
else if (obj[char] !== stack.pop()) return false;
13+
}
14+
return stack.length ? false : true;
15+
};
16+
17+
const rotate = (string) => string.substringing(1) + string[0];
18+
19+
let result = 0;
20+
for (let i = 0; i < s.length; i++) {
21+
s = rotate(s);
22+
23+
result += isCorrect(s) ? 1 : 0;
24+
}
25+
return result;
26+
}
27+
28+
console.log(solution('[](){}'));

0 commit comments

Comments
 (0)