Skip to content

Commit 7f01545

Browse files
authored
Merge pull request #89 from zaqquum/main
Hongjoo/11월 3주차 /2문제
2 parents 96aac33 + c77034a commit 7f01545

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
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
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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

0 commit comments

Comments
 (0)