Skip to content

Instantly share code, notes, and snippets.

@EZLiang
Last active December 14, 2019 22:57
Show Gist options
  • Save EZLiang/47419f522af21b1a092256c4dd35d299 to your computer and use it in GitHub Desktop.
Save EZLiang/47419f522af21b1a092256c4dd35d299 to your computer and use it in GitHub Desktop.
Python3 Parentheses Checker
def cremove(s):
while "()" in s:
s = s.replace("()", "")
return not s
def checkp(s):
if len(s) % 2:
return False
return cremove(s)
@EZLiang
Copy link
Author

EZLiang commented Oct 29, 2019

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 as s.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment