【剑指offer】面试题55 - I. 二叉树的深度(java)
发布日期:2021-04-30 21:02:26 浏览次数:116 分类:精选文章

本文共 651 字,大约阅读时间需要 2 分钟。

??????????????????????????????????????????????????????????????????

???????? [3,9,20,null,null,15,7]?????3?????3???????9????3?????20????1???????????3?

??????? ? 10000?

?????

??TreeNode??

public class TreeNode {    int val;    TreeNode left;    TreeNode right;    TreeNode(int x) {        val = x;    }}

?????

public class Solution {    public int maxDepth(TreeNode root) {        return find(root, 0);    }    private int find(TreeNode root, int num) {        if (root == null) {            return num;        }        return Math.max(find(root.left, num + 1), find(root.right, num + 1));    }}

????????????????????????????????????????0??????????????1?

上一篇:Leetcode--338. 比特位计数
下一篇:CSS浮动

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2026年06月21日 12时42分42秒