Maximum Depth of Binary Tree 分类: Leetcode 算法 2014-10-29 21:16 87人阅读 评论(0) 收藏
2014-10-29 21:16
316 查看
Maximum Depth of Binary Tree
Total Accepted: 36406 TotalSubmissions: 83130
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.
水题
/** * 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 maxDepth(TreeNode *root) { int l,r; if(root==NULL) return 0; else{ l=maxDepth(root->left)+1; r=maxDepth(root->right)+1; } if(l>r) return l; else return r; } };
相关文章推荐
- leetCode(17):Minimum/Maximize depth of binary tree 分类: leetCode 2015-06-21 16:05 146人阅读 评论(0) 收藏
- leetCode(39):Lowest Common Ancestor of a Binary Tree 分类: leetCode 2015-07-17 10:03 114人阅读 评论(0) 收藏
- leetCode(38):Lowest Common Ancestor of a Binary Search Tree 分类: leetCode 2015-07-16 14:48 179人阅读 评论(0) 收藏
- Binary Indexed Tree 分类: ACM TYPE 2014-08-29 13:08 99人阅读 评论(0) 收藏
- leetCode(18):Construct Binary Tree from Preorder and Inorder (Inorder and Postorder) Traversal 分类: leetCode 2015-06-22 08:26 177人阅读 评论(0) 收藏
- Binary Indexed Tree 2D 分类: ACM TYPE 2014-09-01 08:40 95人阅读 评论(0) 收藏
- leetCode(20):Balanced binary tree 分类: leetCode 2015-06-22 08:52 190人阅读 评论(0) 收藏
- leetCode(41):Convert Sorted Array to Binary Search Tree 分类: leetCode 2015-07-17 17:03 95人阅读 评论(0) 收藏
- Convert Sorted Array to Binary Search Tree 分类: Leetcode 2014-12-07 10:49 74人阅读 评论(0) 收藏
- Maximum Depth of Binary Tree
- leetcode-Maximum Depth of Binary Tree
- [leetcode]Maximum Depth of Binary Tree @ Python
- maximum-depth-of-binary-tree
- LeetCode(104)Maximum Depth of Binary Tree
- [Leetcode]Maximum Depth of Binary Tree
- 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