Skip to content

Commit ca46acf

Browse files
committed
[level 2] Title: 괄호 회전하기, Time: 200.20 ms, Memory: 9.23 MB -BaekjoonHub
1 parent df62639 commit ca46acf

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

프로그래머스/2/76502. 괄호 회전하기/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 성능 요약
66

7-
메모리: 10.1 MB, 시간: 196.77 ms
7+
메모리: 9.23 MB, 시간: 200.20 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2024년 09월 18일 16:55:23
19+
2025년 12월 27일 22:48:45
2020

2121
### 문제 설명
2222

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
def solution(s):
22
cnt = 0
33
for i in range(len(s)):
4-
x = (s+s[:i])[i:]
5-
64
stack = []
7-
for j in x:
8-
if stack:
9-
if j == ")" and stack[-1] == "(":
5+
for c in s:
6+
if not stack:
7+
stack.append(c)
8+
elif (stack[-1] == '(' and c == ')') or \
9+
(stack[-1] == '{' and c == '}') or \
10+
(stack[-1] == '[' and c == ']'):
1011
stack.pop()
11-
elif j == "}" and stack[-1] == "{":
12-
stack.pop()
13-
elif j == "]" and stack[-1] == "[":
14-
stack.pop()
15-
else:
16-
stack.append(j)
1712
else:
18-
stack.append(j)
19-
if len(stack) == 0:
13+
stack.append(c)
14+
if not stack:
2015
cnt += 1
16+
s = s[1:] + s[0]
17+
2118
return cnt

0 commit comments

Comments
 (0)