104Maximum Depth of Binary Tree
来源:互联网 发布:oracle sql优化 编辑:程序博客网 时间:2024/05/01 14:02
/**
* 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 leftDepth = 0, rightDepth = 0;
if(root.left!=null){
leftDepth = maxDepth(root.left);
}
if(root.right!=null){
rightDepth = maxDepth(root.right);
}
return Math.max(leftDepth, rightDepth) + 1;
}
}
* 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 leftDepth = 0, rightDepth = 0;
if(root.left!=null){
leftDepth = maxDepth(root.left);
}
if(root.right!=null){
rightDepth = maxDepth(root.right);
}
return Math.max(leftDepth, rightDepth) + 1;
}
}
0 0
- Leetcode 104 Maximum Depth of Binary Tree
- LeetCode(104)Maximum Depth of Binary Tree
- LeetCode 104 Maximum Depth of Binary Tree
- LeetCode: Maximum Depth of Binary Tree [104]
- Leetcode(104)Maximum Depth of Binary Tree
- [leetcode 104] Maximum Depth of Binary Tree
- LeetCode 104 Maximum Depth of Binary Tree
- leetCode #104 Maximum Depth of Binary Tree
- LeetCode 104: Maximum Depth of Binary Tree
- 104Maximum Depth of Binary Tree
- LeetCode 104 Maximum Depth of Binary Tree
- leetcode || 104、Maximum Depth of Binary Tree
- LeetCode 104: Maximum Depth of Binary Tree
- leetcode[104]:Maximum Depth of Binary Tree
- Leetcode[104]-Maximum Depth of Binary Tree
- Leetcode---(104)Maximum Depth of Binary Tree
- leetcode-104-Maximum Depth of Binary Tree
- #104 Maximum Depth of Binary Tree
- 复制一个Dialog后DoModal()返回-1
- 常量指针与指针常量
- Leetcode -- Insertion Sort List
- hdu 1061Rightmost Digit 模幂运算
- Linux下的调试工具
- 104Maximum Depth of Binary Tree
- 求最小的k个数
- hdu 5131 Song Jiang's rank list(模拟)
- HDU 2871 Memory Control(线段树·区间合并·Vector)
- leetcode 128: Longest Consecutive Sequence
- uva 11795 状压dp
- typedef和#define究竟有什么区别?
- Android学习心得(13) --- Android代码混淆(1)
- 软件架构设计