LeetCode 二叉树的最大深度

版权声明:欢迎提问:[email protected] https://blog.csdn.net/include_heqile/article/details/82111620

https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/description/

我的解决方案:

/**
 * 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 Integer.max(maxDepth(root.left), maxDepth(root.right))+1;
    }
}

猜你喜欢

转载自blog.csdn.net/include_heqile/article/details/82111620