We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b808d6d commit e675314Copy full SHA for e675314
Hongjoo/lv1/올바른괄호.py
@@ -0,0 +1,27 @@
1
+def solution(s):
2
+ '''
3
+ 규칙
4
+ - idx = 1 : "(" , 마지막 ")"
5
6
+ answer = True
7
+
8
+ box_match = list()
9
+ if len(s) %2 != 0: # 규칙 1 : 짝수개
10
+ return False
11
+ for i in range(len(s)) :
12
+ # 규칙2 : first = "(" , end = ")" 로 구성됨
13
+ if i == 0 and s[i] == ")" :
14
15
+ elif i == len(s)-1 and s[i] == "(" :
16
17
+ # 규칙 3 : stack 안에서 "()" 조합이 완성되면 pop 하기
18
+ box_match.append(s[i])
19
+ if len(box_match) > 1 : # 2개 이상 들어가 있으면
20
+ if box_match[-2] == "(" and box_match[-1] == ")" : # matching 되면
21
+ x =box_match.pop()
22
+ y =box_match.pop()
23
+ # 규칙 3-1 : box_match 가 남아 있으면 False, 없으면 True
24
+ if len(box_match) > 0 :
25
26
27
+ return True
0 commit comments