Last active
December 14, 2015 16:18
-
-
Save tippenein/5113630 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
// given a sorted array, create a BST | |
public static void add(int[] arr, int start, int end) { | |
int mid = (start + end) / 2; | |
TreeNode n = new TreeNode(arr[mid]); | |
n.left = add(arr, start, mid-1); | |
n.right = add(arr, mid+1, end); | |
return n | |
} | |
public static TreeNode makeBST(int[] arr, int start, int end) { | |
add(arr, 0 arr.length-1); | |
} | |
// bst -> array -> bst |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment