Skip to content

Instantly share code, notes, and snippets.

@hilda8519
Created July 11, 2014 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hilda8519/60367ae3e1a6b4dc0c49 to your computer and use it in GitHub Desktop.
Save hilda8519/60367ae3e1a6b4dc0c49 to your computer and use it in GitHub Desktop.
package minBST;
public class minBST {
class TreeNode{
int val;
TreeNode left;
TreeNode right;
void TreeNode(int x){
val=x;
}
}
TreeNode minBST(int arr[], int start, int end){
if(start<end){
return null;
}
int middle=(start+end)/2;
TreeNode n=new TreeNode(arr[middle]);
n.left=minBST(arr, start, middle-1);
n.right=minBST(arr,midlle+1,end);
return n;
}
TreeNode miniBST(int array[]){
return miniBST(array,0,array.length-1);
}
}
@happyWinner
Copy link

Line 17: (start + end) may cause overflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment