重建二叉树中的盲区求教!!!

代码如下:
public class Solution {
    public TreeNode reConstructBinaryTree(int[] pre,int[] in) {
         TreeNode root = reConstructBinaryTree(pre,0,pre.length-1,in,0,in.length-1);                                                      //这条语句什么意思?TreeNode是接口吗?还有就是括号中的那么一大串是什么意思?
        returnroot;
    }
    privateTreeNode reConstructBinaryTree(int[] pre,intstartPre,intendPre,int[] in,intstartIn,intendIn) {                        //这一条同问。
          
        if(startPre>endPre||startIn>endIn)
            returnnull;
        TreeNode root = new TreeNode(pre[startPre]);                                                                                                  //这里用new ,上面类似的语句怎么不用?
          
        for(inti=startIn;i<=endIn;i++)
            if(in[i]==pre[startPre]){
                root.left=reConstructBinaryTree(pre,startPre+1,startPre+i-startIn,in,startIn,i-1);
                root.right=reConstructBinaryTree(pre,i-startIn+startPre+1,endPre,in,i+1,endIn);
            }
                  
        return  root;
    }
}

全部评论
真诚的回答哈,我觉得你应该先学习java的语法再看这道题。根据你问的问题,大致定位到,函数重载,函数返回值。你看看这两个知识点,然后TreeNode是自己定义的类,再回来理解这道题重建的逻辑,应该会比较清楚了。
点赞 回复 分享
发布于 2018-10-20 08:51
少了一个class,treenode是自己定义的节点类,建议csdn搜,那里很多解答且讲的很细
点赞 回复 分享
发布于 2018-10-19 23:37
TreeNode 树节点吧,括号里的应该是子树的范围 
点赞 回复 分享
发布于 2018-10-19 19:18
那是两个函数 Java是不是也有函数重载?上面是给人用的接口 下面是真正干事的递归函数。你可以理解上面是一身旗袍***的前台,下面是格子衫人字拖的程序员。
点赞 回复 分享
发布于 2018-10-19 18:52

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务