-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgrammers_09.py
More file actions
36 lines (29 loc) · 811 Bytes
/
Programmers_09.py
File metadata and controls
36 lines (29 loc) · 811 Bytes
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
from collections import deque
def right(deq):
stack = []
for check in deq:
if check == '(' or check == '{' or check == '[':
stack.append(check)
if stack:
if check == ')' and stack.pop() != '(':
return False
if check == '}' and stack.pop() != '{':
return False
if check == ']' and stack.pop() != '[':
return False
else: return False
if stack: return False
return True
def solution(s):
answer = -1
deq = deque(_ for _ in s)
print(deq)
count = 0
for i in range(len(s)):
if right(deq):
count += 1
deq.append(deq.popleft())
if count > 1:
return count
else:
return 0