Created
July 1, 2015 08:33
-
-
Save anonymous/ea3764fb618ce8ff66aa to your computer and use it in GitHub Desktop.
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
class Node(object): | |
def __init__(self, val, left=None, right=None): | |
self.val = val | |
self.left = left | |
self.right = right | |
def max_of_tree(root): | |
if not root: | |
return 0 | |
max_left_path = max_of_tree(root.left) | |
max_right_path = max_of_tree(root.right) | |
return max(max_left_path, max_right_path) + root.val | |
node_20 = Node(54) | |
node_21 = Node(55) | |
node_23 = Node(3) | |
node_10 = Node(1, node_20, node_21) | |
node_11 = Node(2, None, node_23) | |
root = Node(1, node_10, node_11) | |
print max_of_tree(root) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment