LeetCode 48 Maximum Depth of Binary Tree
来源:互联网 发布:excel数据加双引号 编辑:程序博客网 时间:2024/06/06 01:39
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就是了。只想说,递归真是二叉树神器。
/*** Definition for binary tree* 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;return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));}}
0 0
- [Leetcode-48]Maximum Depth of Binary Tree
- LeetCode 48 Maximum Depth of Binary Tree
- Leetcode - Tree - Maximum Depth of Binary Tree
- [leetcode][tree] Maximum Depth of Binary Tree
- LeetCode Maximum Depth of Binary Tree
- [Leetcode] Maximum Depth of Binary Tree
- leetcode 24: Maximum Depth of Binary Tree
- [LeetCode] Maximum Depth of Binary Tree
- Leetcode 104 Maximum Depth of Binary Tree
- 【leetcode】Maximum Depth of Binary Tree
- [leetcode]Maximum Depth of Binary Tree
- [LeetCode]Maximum Depth of Binary Tree
- [leetcode]Maximum Depth of Binary Tree
- Leetcode: Maximum Depth of Binary Tree
- LeetCode-Maximum Depth of Binary Tree
- [leetcode] Maximum Depth of Binary Tree
- LeetCode - Maximum Depth of Binary Tree
- LeetCode:Maximum Depth of Binary Tree
- CVTE在线软件专业题
- Android复习练习七(Android中Xml序列化及Pull解析)
- 各种排序方法比较
- RedHat/CentOS发行版本号及内核版本号对照表
- LeetCode-Remove Duplicates from Sorted Array
- LeetCode 48 Maximum Depth of Binary Tree
- android百度地图开发--自定义最短路径搜索图层
- linux 批量修改
- 单链表的选择排序
- Linux 命令记录
- java连接SQL数据库,执行SQL语句
- Linux多线程编程之同步对象编程:线程信号量
- CSS几款超清爽的网页配色代码
- Jsp/Servlet基础-一