-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path괄호 회전하기.py
41 lines (39 loc) · 1.19 KB
/
괄호 회전하기.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from collections import deque
def solution(s):
queue = deque(s)
cnt = 0
for i in range(len(s)):
q = deque()
flag = True
if i != 0:
x = queue.popleft()
queue.append(x)
for j in range(len(s)):
if queue[j] == "[":
q.append("[")
elif queue[j] == "(":
q.append("(")
elif queue[j] == "{":
q.append("{")
elif len(q)>0:
if queue[j] == "]" and q[-1] == "[":
q.pop()
elif queue[j] == "]" and q[-1] != "[":
flag = False
break
elif queue[j] == ")" and q[-1] == "(":
q.pop()
elif queue[j] == ")" and q[-1] != "(":
flag = False
break
elif queue[j] == "}" and q[-1] == "{":
q.pop()
elif queue[j] == "}" and q[-1] != "{":
flag = False
break
elif len(q) == 0:
flag = False
break
if flag and len(q) == 0:
cnt += 1
return cnt