Created
January 23, 2011 12:20
-
-
Save hickford/792036 to your computer and use it in GitHub Desktop.
test if brackets in string are well-nested
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 f(word): | |
open = 0 | |
for x in word: | |
if x == "(": | |
open += 1 | |
elif x == ")": | |
open += -1 | |
if open < 0: | |
return False | |
return open==0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment