Skip to content

Commit

Permalink
10.py 완
Browse files Browse the repository at this point in the history
  • Loading branch information
seongwon02 committed May 20, 2024
1 parent 6515309 commit b8d62fc
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions SWKIM/1to10/10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def solution(s):
answer = 0
check = ['(', '{', '[']
size = len(s)

for i in range(size):
cnt = 0
stack = []
for j in range(size):
if s[(i+j)%size] in check:
stack.append(s[(i+j)%size])
elif s[(i+j)%size] == ')':
if len(stack)!=0 and stack[-1] == '(':
stack.pop()
else:
stack.append(s[(i+j)%size])
elif s[(i+j)%size] == '}':
if len(stack)!=0 and stack[-1] == '{':
stack.pop()
else:
stack.append(s[(i+j)%size])
elif s[(i+j)%size] == ']':
if len(stack)!=0 and stack[-1] == '[':
stack.pop()
else:
stack.append(s[(i+j)%size])

if len(stack) == 0:
answer += 1

return answer

0 comments on commit b8d62fc

Please sign in to comment.