1. 题目

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.

2. 思路

递归到左、右子树的max值,+1.

3. 代码

/*** 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 == NULL) { return 0; }return 1 + max(maxDepth(root->left), maxDepth(root->right));}
};

【leetcode】104. Maximum Depth of Binary Tree相关推荐

  1. 【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 ...

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

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

  3. 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 ...

  4. 【LeetCode从零单排】No104 Maximum Depth of Binary Tree

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

  5. LeetCode: 104. Maximum Depth of Binary Tree

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

  6. leetcode python3 简单题104. Maximum Depth of Binary Tree

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百零四题 (1)题目 英文: Given a binary tree, find ...

  7. leetcode 104. Maximum Depth of Binary Tree

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

  8. [swift] LeetCode 104. Maximum Depth of Binary Tree

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

  9. Leet Code OJ 104. Maximum Depth of Binary Tree [Difficulty: Easy]

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

最新文章

  1. java http head 请求_http请求头header、请求体body、请求行介绍
  2. 操作系统期末复习知识点
  3. ActiveMQ专题
  4. Vs2010无法打开文件“Kernel32.lib”、无法打开“libcpmt.lib”msvcprt.lib
  5. 题外:分类篇(音乐风格分类)基于BP神经网络
  6. 笔记本通过网口控制单片机_国产又推出笔记本:旋转屏,自带RS-232串口和网口,工程师专用...
  7. 模型算法_生产建模型 算法控效率
  8. 登录服务器信息怎么删除,服务器端删除了用户,怎么通知客户端浏览器删除cookie...
  9. 全网首发:VS编译的文件不在指定位置,怎么办
  10. Python模块安装:Python3安装pdfminer3k
  11. oracle 密码过期处理
  12. GCD深入学习之GCD的初识
  13. java 模板模式_java设计模式之模板方法模式详解
  14. Tableau自定义分类调色板
  15. 国外可以发外链的网站,外贸网站外链平台
  16. 练手——蚂蚁二面笔试题
  17. (附源码)spring boot大学生综合素质测评系统 毕业设计 162308
  18. 50个极好的bootstrap模板下载地址
  19. 服务器ssl证书安装
  20. 操作系统形式化验证实践教程(7) - C代码的自动验证

热门文章

  1. cppcheck值得注意的一些筛选项
  2. 使用引用的方式交换数据的数值
  3. C++ primer第六章6.6函数匹配
  4. Java基础——Java反射机制及IoC原理
  5. H264基本概念之 宏块、片和片组
  6. 多个 VUE 前端工程部署设置、nginx 代理配置
  7. Java List<T>去重方法,引用类型集合去重
  8. java 对 redis 的基本操作
  9. vue中的slot插槽
  10. PowerDesigner表结构和字段大小写转换