LeetCode--Maximum Depth of Binary Tree
来源:互联网 发布:java android sdk 编辑:程序博客网 时间:2024/06/16 02:04
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 a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int maxDepth(TreeNode* root) { if(!root) return 0; return max(maxDepth(root->left),maxDepth(root->right))+1; }};
阅读全文
0 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
- 日本西粟仓村政府计划发起ICO,振兴地方经济
- 网络请求重定向
- iOS 图片涂鸦功能
- leetcode
- php读取富文本编辑器编辑后的文章内容,并去除所有html标签、空格以及空白,截取字符串(包括中文)
- LeetCode--Maximum Depth of Binary Tree
- 读懂正则表达式就这么简单
- C#算法系列(2)——线索二叉树
- 因子分解
- 第十三周项目一(3)——验证二叉排序树相关算法
- 阿里云配置tomcat后外网不能访问的问题
- JAVA Maven SpringMVC Mybatis bootstrap信息(增删改查分页)实战
- Android 中的一些基本依赖
- vue中使用daterangepicker遇到的小问题