leetcode-104-二叉树深度

来源:互联网 发布:软件开发 书籍 知乎 编辑:程序博客网 时间:2024/05/29 12:47
public class Solution {    /*public int maxDepth(TreeNode root) {        if (root == null) return 0;        int left = 1, right = 1;        left += maxDepth(root.left);        right += maxDepth(root.right);        return left > right ? left : right;    }*/    public int maxDepth(TreeNode root) {        if (root == null) return 0;        int left, right;        left = maxDepth(root.left);        right = maxDepth(root.right);        return Math.max(left, right) + 1;    }}
0 0
原创粉丝点击