From b8d62fc1312871d04bb1937b3ea6953008a92bf2 Mon Sep 17 00:00:00 2001 From: seongwon02 Date: Tue, 21 May 2024 02:52:01 +0900 Subject: [PATCH] =?UTF-8?q?10.py=20=EC=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SWKIM/1to10/10.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 SWKIM/1to10/10.py diff --git a/SWKIM/1to10/10.py b/SWKIM/1to10/10.py new file mode 100644 index 0000000..7fda14f --- /dev/null +++ b/SWKIM/1to10/10.py @@ -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 +