Created
July 10, 2016 23:01
-
-
Save ta1hia/f5f34a21eeca7017fad52d5cb537916f to your computer and use it in GitHub Desktop.
dropbox example q
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
def rebluebluered(s, pattern): | |
return search(s, pattern, dict()) | |
def search(left, pattern, matches): | |
if (not pattern and left) or (pattern and not left): | |
return False | |
if not pattern and not left: | |
return True | |
pch = pattern[0] | |
if matches.get(pch): | |
word = matches[pch] | |
if left.find(word) == 0: | |
return search(left[len(word):], pattern[1:], matches) | |
else: | |
return False | |
word = "" | |
for i, c in enumerate(left): | |
word += c | |
matches[pch] = word | |
print(matches, left, pch) | |
if search(left[i+1:], pattern[1:], matches): | |
return True | |
matches.pop(pch) | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment