Last active
December 14, 2019 22:57
-
-
Save EZLiang/47419f522af21b1a092256c4dd35d299 to your computer and use it in GitHub Desktop.
Python3 Parentheses Checker
This file contains 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
def cremove(s): | |
while "()" in s: | |
s = s.replace("()", "") | |
return not s | |
def checkp(s): | |
if len(s) % 2: | |
return False | |
return cremove(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python3 Parentheses Checker
Python3 Parentheses Checker is the fastest parentheses checker.
How to use
Just format the string of parentheses as a string and pass it to
checkp
ass
.How it works
P3PC first does a very quick check to make sure the length is even. Then, P3PC removes pairs of parentheses (
()
) until it can't. Then P3PC checks to see if the result is the null string.