Created
July 11, 2014 19:18
-
-
Save hilda8519/60367ae3e1a6b4dc0c49 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
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 17: (start + end) may cause overflow