Skip to content

Instantly share code, notes, and snippets.

@ejcer
Created November 9, 2015 01:05
Show Gist options
  • Save ejcer/af7635dff152c494ce35 to your computer and use it in GitHub Desktop.
Save ejcer/af7635dff152c494ce35 to your computer and use it in GitHub Desktop.
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