leetcode--Maximum Depth of Binary Tree
来源:互联网 发布:勇者之塔魂力进阶数据 编辑:程序博客网 时间:2024/05/29 16:55
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.
解题思路:使用递归思路,求最大的左子树和最大的右子树的最大。
java版:
public class Solution { public int maxDepth(TreeNode root) { if(root==null) return 0; else return Math.max(maxDepth(root.left),maxDepth(root.right))+1; }}
c++版:
class Solution {public: int maxDepth(TreeNode* root) { if(root==NULL) return 0; else return max(maxDepth(root->left),maxDepth(root->right))+1; }};
1 0
- 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
- LeetCode | Maximum Depth of Binary Tree
- 【leetcode】Maximum Depth of Binary Tree
- 一个例子让你了解Java反射机制
- Java虚拟机类加载机制+案例分析
- Gradle for Android 第七篇( Groovy入门 )
- membercache使用笔记
- 38.windbg-调试技巧(创建进程即断下、r修改控制条件跳转)
- leetcode--Maximum Depth of Binary Tree
- Eclipse Logcat 显示配置
- 使用datatable后台分页
- Leetcode:28. Implement strStr()(JAVA)
- 去掉String字符串的最后一个字符
- Java集合框架:总结
- adb logcat 命令行用法
- 移动端H5做一个不限个数的通栏按钮 by FungLeo
- java中图片格式转换