when I call this function, why there is a stackoverflow error? I have checked my terminal conditions but can not figure out where the problem is.
public static TreeNode buildTree(int t1, int t2, ListNode[] nodeArray) {
if(t1 == t2){
TreeNode temp = new TreeNode(nodeArray[t1].val);
temp.left = null;
temp.right = null;
return temp;
}
else if(t1 > t2){
return null;
}
else{
TreeNode root = new TreeNode(nodeArray[(t1+t2)/2].val);
root.left = buildTree(0,(t1+t2)/2-1,nodeArray);
root.right = buildTree((t1+t2)/2+1,nodeArray.length-1,nodeArray);
return root;
}
}
buildTree.