Created
November 9, 2015 01:05
-
-
Save ejcer/af7635dff152c494ce35 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
public static int[] diff(Node head, int height){ | |
if(head.left == null && head.right == null){ | |
int[] base = new int[2]; | |
base[0] = 0; | |
base[1] = 0; | |
} | |
int[] left = new int[2]; | |
left[0] = Integer.MAX_VALUE; | |
left[1] = Integer.MIN_VALUE; | |
if(head.left != null){ | |
left = diff(head.left, height+1); | |
} | |
int[] right = new int[2]; | |
right[0] = Integer.MAX_VALUE; | |
right[1] = Integer.MIN_VALUE; | |
if(head.right != null){ | |
right = diff(head.right, height+1); | |
} | |
int[] minmax = new int[2]; | |
minmax[0] = 1+Math.min(left[0], right[0]); | |
minmax[1] = 1+Math.max(left[1], right[1]); | |
return minmax; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment