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 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]相关推荐
- 【LeetCode 剑指offer刷题】树题4:104 Maximum Depth of Binary Tree
[LeetCode & 剑指offer 刷题笔记]目录(持续更新中...) 104. Maximum Depth of Binary Tree Given a binary tree, fin ...
- 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 ...
- 【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 ...
- 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 ...
- 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 ...
- 【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 ...
- leetcode python3 简单题104. Maximum Depth of Binary Tree
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百零四题 (1)题目 英文: Given a binary tree, find ...
- [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 ...
- 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 ...
最新文章
- SAP ECC 6.0 ,R3 windows server 2003 安装分享 自学教程
- AspNetDB.mdf数据库的建立和使用
- 数据库查询某一列大写转化小写字母表示_基于MySQL数据库下亿级数据的分库分表...
- 向linux内核版本号添加字符/为何有时会自动添加“+”号
- python 接口自动化_Python 接口自动化测试
- Idea中搭建Wildfly(JBoss)运行环境(Mac)
- Qt文档阅读笔记-数据驱动测试
- opencv 识别机车
- 数据集的非均衡问题(imbalanced data)和应对方法
- 华为主题锁屏壁纸换不掉_华为手机中的这些默认设置一定要改,不然会导致手机卡顿加快耗电...
- XenApp/XenDesktop快速部署工具- QDT for 7.6 LTSR
- vs2017激活密钥
- 压力测试流程及测试步骤
- Python使用scrapy爬取阳光热线问政平台过程解析
- 智能家居的新想法(2022)
- 斯坦福AI百年报告2017:人工智能与机器学习全景式概览
- java开发用win7好还是win10_win10和win7哪个好用|两个系统的性能比较
- [473]tf.nn.*()函数and tf.add()函数
- 数字化时代:电梯广告的喜与忧
- PC端直通车投放 直通车属性投放 淘宝直通车的四种玩法,你会几种?