Last active
September 8, 2019 09:13
-
-
Save shoark7/59df58b63b2e87b95da7dfe871eda4e7 to your computer and use it in GitHub Desktop.
주어진 괄호식이 올바른 괄호식인지 검증한다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""괄호식을 입력받아 이 괄호식이 옳은 형태의 괄호식인지 검증하라 | |
:입력: str | `(`와 `)`로 구성된 문자열. 길이는 0 이상. (ex: `(())()()`) | |
:출력: bool | 입력 문자열이 올바른 괄호인지 아닌지의 여부. (ex: `True`) | |
:조건: | |
1. 입력에는 `()` 이외의 그 어떤 글자도 들어오지 않는다. | |
""" | |
def is_right_parenthesis(parens): | |
OPENER, CLOSER = '()' | |
counter = 0 | |
for p in parens: | |
counter += (1 if p == OPENER else -1) | |
if counter < 0: | |
return False | |
return counter == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment