LeetCode 104 Maximum Depth of Binary Tree JAVA

来源:互联网 发布:网络电视需要什么设备 编辑:程序博客网 时间:2024/05/16 04:47

代码如下,递归。

public class Solution {

    public int maxDepth(TreeNode root) {
        if (root == null) return 0;
        int left = maxDepth(root.left);
        int right = maxDepth(root.right);
        return 1 + (left > right ? left : right);
    }
}
0 0
原创粉丝点击