Skip to content

Commit f3bbf04

Browse files
committed
99차 3번 문제풀이
1 parent d10c353 commit f3bbf04

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

live9/test99/문제3/백유진.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def solution(s):
2+
answer = 0
3+
4+
for i in range(len(s)):
5+
ns = s[i:] + s[:i]
6+
7+
stack = []
8+
isValid = True
9+
10+
for n in ns:
11+
if n == '(' or n == '{' or n == '[':
12+
stack.append(n)
13+
else:
14+
if not stack:
15+
isValid = False
16+
break
17+
top = stack[-1]
18+
if n == ')' and top == '(' or n == '}' and top == '{' or n == ']' and top == '[':
19+
stack.pop()
20+
else:
21+
isValid = False
22+
break
23+
if isValid and not stack:
24+
answer += 1
25+
26+
return answer

0 commit comments

Comments
 (0)