File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 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+ return False
15+ elif i == len (s )- 1 and s [i ] == "(" :
16+ return False
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+ return False
26+
27+ return True
Original file line number Diff line number Diff line change 1+ def solution (s ):
2+ answer = 1
3+ match_box = list ()
4+ for i in range (len (s )) :
5+ match_box .append (s [i ])
6+ if len (match_box ) > 1 :
7+ if match_box [- 2 ] == match_box [- 1 ] :
8+ match_box .pop ()
9+ match_box .pop ()
10+
11+ if len (match_box ) > 0 :
12+ return 0
13+
14+ return answer
You can’t perform that action at this time.
0 commit comments