Created
July 3, 2012 13:23
-
-
Save nashibao/3039677 to your computer and use it in GitHub Desktop.
example answer..
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
codes = {} | |
def convert(tag): | |
return codes.setdefault(tag, 1 << codes.length) | |
def desc(node): | |
for child in node.childs: | |
child_code = convert(child.tag) | |
child.code = child_code | node.code | |
if bool(child_code & node.code): | |
print 'gotcha!!' | |
desc(child) | |
root.code = convert(root.tag) | |
desc(root) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment