We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7893904 commit a419d52Copy full SHA for a419d52
1 file changed
live9/test99/문제3/조진우.js
@@ -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