Created
May 16, 2015 18:39
-
-
Save prongs/fdcbc6c002a2b5822155 to your computer and use it in GitHub Desktop.
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
class Node: | |
Node left | |
Node right | |
int data | |
int prime_depth # extra space | |
int path_size # extra space | |
global max_path_size = -1 | |
global max_path_node = None | |
def calculate_max_path_node(root): | |
calculate_max_path_node(root.left) | |
calculate_max_path_node(root.right) | |
if data is not prime: | |
root.prime_depth = 0 | |
root.path_size = 0 | |
else: | |
root.prime_depth = 1 + max(root.left.prime_depth, root.right.prime_depth) | |
root.path_size = 1 + root.left.prime_depth + root.right.prime_depth | |
if root.path_size > max_path_size: | |
max_path_size = root.path_size | |
max_path_node = root | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment