[leetcode][tree] Maximum Depth of Binary Tree
2015-05-20 20:45
323 查看
题目:
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.
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 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(NULL == root) return 0; return 1+max(maxDepth(root->left), maxDepth(root->right)); } };
相关文章推荐
- Leetcode: Maximum Depth of Binary Tree
- leetcode 第104题 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
- Maximum Depth of Binary Tree ---LeetCode
- [leetcode]Maximum Depth of Binary Tree
- 【LeetCode】Maximum Depth of Binary Tree
- (java)leetcode Maximum Depth of Binary Tree
- 【LeetCode】Maximum Depth of Binary Tree&&Same Tree
- [LeetCode#104, 111]Maximum Depth of Binary Tree, Minimum 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)