-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path괄호 회전하기.py
67 lines (53 loc) · 1.45 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'''
def solution(s):
def check(s):
stack = []
while s:
stack.append(s.pop(0))
while True:
if len(stack) >= 2:
if stack[-1] == ']' and stack[-2] == '[':
stack.pop()
stack.pop()
continue
if stack[-1] == ')' and stack[-2] == '(':
stack.pop()
stack.pop()
continue
if stack[-1] == '}' and stack[-2] == '{':
stack.pop()
stack.pop()
continue
break
if not stack:
return True
return False
s = list(s)
answer = 0
for _ in range(len(s)):
s.append(s.pop(0))
if check(s[:]):
answer += 1
return answer
'''
#2022.11.16
from collections import deque
def check_bracket(s):
s = ''.join(list(s))
for _ in range(len(s)//2):
s_copy = s[:]
s = s.replace('()','')
s = s.replace('{}','')
s = s.replace('[]','')
if not s:
return True
if s == s_copy:
return False
def solution(s):
s = deque(s)
answer = 0
for _ in range(len(s)):
s.append(s.popleft())
if check_bracket(list(s)):
answer += 1
return answer