首页 > 其他分享 >104. Maximum Depth of Binary Tree

104. Maximum Depth of Binary Tree

时间:2022-11-19 19:12:27浏览次数:33  
标签:Binary right int Tree Depth maxDepth root left

Given a binary tree, find its maximum depth.

The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

 

class Solution {

    public int maxDepth(TreeNode root) {

        if (root == null)

            return 0;

       int left = maxDepth(root.left);

       int right= maxDepth(root.right);

       return 1 + Math.max(left, right);

    }

}

标签:Binary,right,int,Tree,Depth,maxDepth,root,left
From: https://www.cnblogs.com/MarkLeeBYR/p/16906779.html

相关文章

  • 98. Validate Binary Search Tree
    Givenabinarytree,determineifitisavalidbinarysearchtree(BST).AssumeaBSTisdefinedasfollows:Theleftsubtreeofanodecontainsonlynodesw......
  • js树形组件zTree简单使用
    <!DOCTYPEhtml><html><head><title>ZTREEDEMO</title><metahttp-equiv="content-type"content="text/html;charset=UTF-8"/><linkrel="stylesh......
  • 1102 Invert a Binary Tree
    ThefollowingisfromMaxHowell@twitter:Google:90%ofourengineersusethesoftwareyouwrote(Homebrew),butyoucan'tinvertabinarytreeonawhiteboa......
  • elementUI tree树节点文字超出时省略或折行 样式
    文字超出时折行::v-deep.tree{width:100%;.el-tree-node{white-space:normal;.el-tree-node__content{height:100%;a......
  • monodepth2如何跑代码?
    代码链接:​​https://github.com/nianticlabs/monodepth2​​论文链接:​​​ICCV2019(arXivpdf)​​1.环境配置#创建一个新的环境condacreate-nmonodepth2python==3......
  • TreeUtils工具类一行代码实现列表转树 实战Java8 三级菜单 三级分类 附视频
    一、序言在日常一线开发过程中,总有列表转树的需求,几乎是项目的标配,比方说做多级菜单、多级目录、多级分类等,有没有一种通用且跨项目的解决方式呢?帮助广大技术朋友给业务瘦......
  • Caused by: android.view.InflateException: Binary XML file line #2 in com.example
    在学习《Android第一行代码》的14.5章节深色主题的内容时,该章节是以MaterialTest项目作为示例的,并且在res目录下创建了一个values-29目录,在values-29目录下又创建了一个sty......
  • Codeforces 1646 D. Weight the Tree
    题意给你n个节点的树,让你给每个节点进行赋值,并且赋的值需要为正整数;同时当一个节点的值等于所有邻居节点的值的和时,这个点为好点;求出一组赋值情况,满足树的好点个数最大......
  • el-tree 初始加载中状态
    问题二次封装了一个el-tree组件MenuTree,想要在树形数据nodeData传递之前,树显示为loading加载中的状态。原代码是在MenuTree中监听nodeData,data中声明treeLo......
  • el-tree 的 setCheckedKeys() 无效
    问题打开对话框时,加载里面的树,并且勾选默认节点。在对话框中监听dialogOpen为true时就调用el-tree的setCheckedKeys()方法。但是总是报错无法读取树。试过$next......