LeetCode——Maximum Depth of Binary Tree

Question

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.

Answer

/*** Definition for a binary tree node.* struct TreeNode {*     int val;*     TreeNode *left;*     TreeNode *right;*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}* };*/class Solution {
public:// 求树的高度int maxDepth(TreeNode* root) {if (!root)return 0;else {int i = maxDepth(root->left);int j = maxDepth(root->right);return max(i, j) + 1;}}
};

转载于:https://www.cnblogs.com/zhonghuasong/p/6658654.html

LeetCode——Maximum Depth of Binary Tree相关推荐

  1. LeetCode Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  2. Leetcode: Maximum Depth of Binary Tree

    题目:算出二叉树的最大深度 解决方案:(1)BFS (2)DFS (1)BFS 一层一层往下搜索,一直找到最深的点,这里由于节点的val是没有用的,所以可以用来存储当前节点的深度,然后注意指针一定要初 ...

  3. LeetCode - Maximum Depth of Binary Tree

    递归求二叉树的最大深度. /*** Definition for binary tree* public class TreeNode {* int val;* TreeNode left;* Tre ...

  4. LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree

    LeetCode:Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth ...

  5. 【LeetCode 剑指offer刷题】树题4:104 Maximum Depth of Binary Tree

    [LeetCode & 剑指offer 刷题笔记]目录(持续更新中...) 104. Maximum Depth of Binary Tree Given a binary tree, fin ...

  6. Leetcode | Minimum/Maximum Depth of Binary Tree

    Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...

  7. 【LeetCode】104. Maximum Depth of Binary Tree (2 solutions)

    Maximum Depth of Binary Tree  Given a binary tree, find its maximum depth. The maximum depth is the ...

  8. 领扣-104/111 二叉树的最大深度 Maximum Depth of Binary Tree MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  9. LC 104. Maximum Depth of Binary Tree

    1.题意 104. Maximum Depth of Binary Tree Easy 98540 Given a binary tree, find its maximum depth. The m ...

最新文章

  1. 自动化Build的方法如下所示
  2. removelogo使用方法_怎么给视频去水印?这三种方法简单又高效
  3. js函数中的参数的个数
  4. Codeforces 1196F K-th Path
  5. Oracle10g数据库归档与非归档模式下的备份与恢复
  6. 最全BAT前端开发面试80题:算法+html+js+css!含答案大赠送!
  7. 基于深度学习的异构时序事件患者数据表示学习框架
  8. Scala 深入浅出实战经典 第91讲:Akka第一个案例动手实战架构设计
  9. 阶段1 语言基础+高级_1-3-Java语言高级_08-JDK8新特性_第1节 常用函数接口_15_常用的函数式接口_Predicate接口练习-集合信息的筛选...
  10. 通达\铭心联手,共探企业信息化营销新机遇
  11. PLC控制一阶惯性纯滞后系统的大林(Dahlin)算法详解(SCL代码)
  12. 喜欢的现代诗 -。-
  13. C++基础学习-33模板全特化、偏特化(局部特化)
  14. 代码风格自动化(二)——husky + lint-staged
  15. 亚马逊跨境电商和国内的电商平台哪个好?
  16. Linux 命令————打包解压之tar
  17. 9种常用的软件容错处理方式
  18. vue项目中表格删除数据页码显示注意点
  19. 电商APP源码功能解说
  20. php 获取配置信息,PHP系统配置信息的获取

热门文章

  1. ubuntu下vlc-android编译
  2. 档案盒正面标签制作_如何制作差异化的短视频内容?
  3. android 圆点指示器,ViewPager加上小圆点指示器效果
  4. 【CCCC】L2-006 树的遍历 (25分),根据后序与中序遍历建立二叉树(我讨厌树,系列1)
  5. 【CSP201312-2】ISBN号码,字符串,简单模拟
  6. CodeVs天梯青铜Bronze题解
  7. java timer 返回值,如何让计时器返回java时间
  8. 第六章节 三层架构(二. 模型层与数据访问层)
  9. Glad You Came--带条件的线段树区间更新,区间查询(其实是单点查询)
  10. linux 配置mq队列,Apache ActiveMQ 消息队列安装与配置