Skip to content

Commit 9cbfdba

Browse files
committed
[PGS]올바른 괄호/lv2/60min
1 parent 2ebd4e5 commit 9cbfdba

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Hongjoo/lv2/올바른괄호.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
def solution(s):
2+
answer = True
3+
print(s)
4+
#1. s은 ( 로 시작, ) 가 끝
5+
if s[0] == ")":
6+
answer = False
7+
return answer
8+
elif s[-1] == "(":
9+
answer = False
10+
return answer
11+
#2.) 와 (의 개수 동일
12+
left = 0
13+
right = 0
14+
for n in s :
15+
if n == "(":
16+
left +=1
17+
elif n == ")":
18+
right +=1
19+
else:
20+
answer = False
21+
return answer
22+
23+
if left != right :
24+
answer = False
25+
return answer
26+
27+
28+
return True

0 commit comments

Comments
 (0)