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.

求二叉树的最大深度

/*** Definition for a binary tree node.* public class TreeNode {*     int val;*     TreeNode left;*     TreeNode right;*     TreeNode(int x) { val = x; }* }*/
public class Solution {public int maxDepth(TreeNode root) {if (root == null) {return 0;}int left = maxDepth(root.left);int right = maxDepth(root.right);return Math.max(left, right) + 1;}
}

转载于:https://www.cnblogs.com/iwangzheng/p/5768592.html

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

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

  2. [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 ...

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

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

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

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

  6. LeetCode 104. Maximum Depth of Binary Tree--二叉树高度--递归或迭代--C++,Python解法

    题目地址:Maximum Depth of Binary Tree - LeetCode Given a binary tree, find its maximum depth. The maximu ...

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

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

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

  9. 【leetcode】104. Maximum Depth of Binary Tree

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

最新文章

  1. 你真的了解软件测试行业吗?
  2. mysql mydumper_采用mydumper对MySQL部分数据库进行热备
  3. 面向对象和面向过程,python中的类class,python中程序的入口——main方法,
  4. java条件触发_java – 当给定75:android时,条件不会触发
  5. 深圳华为 C++面试题
  6. 栅栏密码怎么写java程序_[CTF]栅栏密码学习
  7. Android Studio开发引入Speex
  8. 海淘也疯狂 跨境电商网站8月监测报告
  9. 手机通信专有名词中英文
  10. 微信小程序云函数数组删除和添加并排序操作pull,push 用法
  11. SQP 序列二次规划法
  12. php开发之Composer包
  13. php获得opcode,php opcode 缓存
  14. python系列tkinter之pack布局、place布局和grid布局
  15. 2022年欧莱雅-联合国教科文组织 “世界杰出女科学家成就奖”获奖人名单公布...
  16. 打开excel,提示 flash play2 错误,解决办法
  17. java 羽化_JAVA10来了 - 羽化布凉的个人空间 - OSCHINA - 中文开源技术交流社区
  18. java 摩尔斯电码_Java实现 LeetCode 804 唯一摩尔斯密码词 (暴力)
  19. Linux知识点总结
  20. (导航页)OpenStack-M版-双节点手工搭建-附B站视频

热门文章

  1. 02如何抓住重点,系统高效地学习数据结构与算法?
  2. Lucene学习总结之三:Lucene的索引文件格式(2)
  3. C# System.Windows.Forms.NumericUpDown 控件全选其中文字
  4. spring-使用配置文件完成JdbcTemplate操作数据库
  5. MySQL数据库的datetime与timestamp
  6. cacti 被监控机器snmp 配置
  7. 构建LAMP平台及应用系统
  8. Jfinal 显示欢迎页 index.jsp
  9. “人肉”背后隐藏的网络风险
  10. 如何进行服务器选购[转]