leetcode 日经贴,Cpp code -Maximum Depth of Binary Tree
2015-04-21 17:17
399 查看
Maximum Depth of Binary Tree
/** * 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) { if (!root) { return 0; } if (!root->left && !root->right) { return 1; } return 1 + max(maxDepth(root->left), maxDepth(root->right)); } };
相关文章推荐
- leetcode 日经贴,Cpp code -Minimum Depth of Binary Tree
- Leetcode: 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)