Leetcode: Maximum Depth of Binary Tree
LeetCode of Tree Binary maximum depth
2023-09-11 14:14:08 时间
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.
1 /** 2 * Definition for binary tree 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeNode(int x) { val = x; } 8 * } 9 */ 10 public class Solution { 11 public int maxDepth(TreeNode root) { 12 if(root==null) return 0; 13 return Math.max(maxDepth(root.left), maxDepth(root.right))+1; 14 } 15 }
相关文章
- Leetcode: 24 Game
- Leetcode: Stream of Characters
- Leetcode: Subtree of Another Tree
- Leetcode: First Unique Character in a String
- Leetcode: Minimum Depth of Binary Tree
- English Voice of <<All Of Me>>
- [LeetCode]Sum of Two Integers
- [LeetCode] Remove Nth Node From End of List
- 【LeetCode】236. Lowest Common Ancestor of a Binary Tree
- 【LeetCode】201. Bitwise AND of Numbers Range
- 【LeetCode】45. Jump Game II
- LeetCode_Maximum Depth of Binary Tree
- [LeetCode] 1339. Maximum Product of Splitted Binary Tree 分裂二叉树的最大乘积
- [LeetCode] 1333. Filter Restaurants by Vegan-Friendly, Price and Distance 餐厅过滤器
- [LeetCode] 1296. Divide Array in Sets of K Consecutive Numbers 划分数组为连续数字的集合
- [LeetCode] 1266. Minimum Time Visiting All Points 访问所有点的最小时间
- [LeetCode] 1170. Compare Strings by Frequency of the Smallest Character 比较字符串最小字母出现频次
- [LeetCode] 1010. Pairs of Songs With Total Durations Divisible by 60 总持续时间可被60整除的歌曲
- [LeetCode] 559. Maximum Depth of N-ary Tree N叉树的最大深度
- [LeetCode] Subtree of Another Tree 另一个树的子树
- [LeetCode] Reverse Vowels of a String 翻转字符串中的元音字母
- [LeetCode] 235. Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最小共同父节点
- [LeetCode] 111. Minimum Depth of Binary Tree 二叉树的最小深度
- leetcode 695. Max Area of Island 岛屿的最大面积(中等)