LeetCode: Depth of Binary Tree
来源:互联网 发布:java事务 编辑:程序博客网 时间:2024/04/29 10:49
Problem:
Given a binary tree, find its depth (maximum height).
递归求解。
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int maxHeight(TreeNode *root) { // Start typing your C/C++ solution below // DO NOT write int main() function if (root == NULL) return 0; int left = maxHeight(root->left) + 1; int right = maxHeight(root->right) + 1; return left > right ? left : right; }};
- LeetCode: Depth of Binary Tree
- Leetcode - Tree - Maximum Depth of Binary Tree
- [leetcode][tree] Maximum Depth of Binary Tree
- LeetCode: Minimum Depth of Binary Tree
- LeetCode Maximum Depth of Binary Tree
- [Leetcode] Minimum Depth of Binary Tree
- [Leetcode] Maximum Depth of Binary Tree
- LeetCode : Minimum Depth of Binary Tree
- leetcode 24: Maximum Depth of Binary Tree
- leetcode 31: Minimum Depth of Binary Tree
- [LeetCode] Minimum Depth of Binary Tree - BFS
- [LeetCode] Minimum Depth of Binary Tree - DFS
- [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】Minimum Depth of Binary Tree
- LeetCode:Minimum Depth of Binary Tree
- 详解Java中的闭包(Closure)和回调
- 用Java泛型实现2-路插入排序
- Khan公开课 - 统计学学习笔记:(六)中心极限定理
- Hdu 1621 - Pipe Fitters 计算几何
- android ImageSwitcher和Gallery组合使用
- LeetCode: Depth of Binary Tree
- map与hash_map
- 自制精美易用的DBGrid
- 使用createview切分视图窗口
- 快速排序
- 处理7z格式的001、002……文件
- 数据库中数据库与表的创建
- POJ 1091 跳蚤
- 良好的用户体验来源于贴心的功能(一)-谈如何设计记录用户切换的输入法