leetcode 104. Maximum Depth of Binary Tree

来源:互联网 发布:龙章贵事件知乎 编辑:程序博客网 时间:2024/05/18 01:55
/**     * 104. Maximum Depth of Binary Tree     * @param root     * @return     * 2017年3月3日上午11:16:00     */    public int maxDepth(TreeNode root) {    TreeNode pTreeNode = root;        if (pTreeNode == null)    return 0;    else {    int leftDep = maxDepth(pTreeNode.left)+1;    int rightDep = maxDepth(pTreeNode.right)+1;    return leftDep>=rightDep?leftDep:rightDep;    }    }

0 0
原创粉丝点击