题目:
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 leftnum=0;if(root.left!=null){leftnum=maxDepth(root.left);}int rightnum=0;if(root.right!=null){rightnum=maxDepth(root.right);}if(leftnum>rightnum){return leftnum+1;}else{return rightnum+1;}}
}

Leet Code OJ 104. Maximum Depth of Binary Tree [Difficulty: Easy]相关推荐

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

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

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

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

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

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

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

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

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

  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. 104. Maximum Depth of Binary Tree (Easy)

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

最新文章

  1. SAP ECC 6.0 ,R3 windows server 2003 安装分享 自学教程
  2. AspNetDB.mdf数据库的建立和使用
  3. 数据库查询某一列大写转化小写字母表示_基于MySQL数据库下亿级数据的分库分表...
  4. 向linux内核版本号添加字符/为何有时会自动添加“+”号
  5. python 接口自动化_Python 接口自动化测试
  6. Idea中搭建Wildfly(JBoss)运行环境(Mac)
  7. Qt文档阅读笔记-数据驱动测试
  8. opencv 识别机车
  9. 数据集的非均衡问题(imbalanced data)和应对方法
  10. 华为主题锁屏壁纸换不掉_华为手机中的这些默认设置一定要改,不然会导致手机卡顿加快耗电...
  11. XenApp/XenDesktop快速部署工具- QDT for 7.6 LTSR
  12. vs2017激活密钥
  13. 压力测试流程及测试步骤
  14. Python使用scrapy爬取阳光热线问政平台过程解析
  15. 智能家居的新想法(2022)
  16. 斯坦福AI百年报告2017:人工智能与机器学习全景式概览
  17. java开发用win7好还是win10_win10和win7哪个好用|两个系统的性能比较
  18. [473]tf.nn.*()函数and tf.add()函数
  19. 数字化时代:电梯广告的喜与忧
  20. PC端直通车投放 直通车属性投放 淘宝直通车的四种玩法,你会几种?

热门文章

  1. 启动sqlserver_微软的 SQL Server 你学会了吗?
  2. HDU4514(非连通图的环判断与图中最长链)
  3. Delphi之virtual,dynamic,abstract
  4. 使用PowerDbg自动化Windbg调试过程
  5. Notepad++ 去除CRLF符号
  6. 阿里开源的Arthas竟然还不会用?最佳实践来了!
  7. SQL 查询语句总是先执行 SELECT?
  8. C++突破private的方案
  9. Django模型(一)
  10. 音视频技术开发周刊 | 238