其他分享
首页 > 其他分享> > 剑指 Offer 55 - I. 二叉树的深度

剑指 Offer 55 - I. 二叉树的深度

作者:互联网

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    public int maxDepth(TreeNode root) {
        if(root == null) return 0;
        return Math.max(maxDepth(root.left),maxDepth(root.right)) + 1;
    }


}

标签:right,TreeNode,Offer,55,int,二叉树,return,root,maxDepth
来源: https://www.cnblogs.com/vccyb/p/14644067.html