LeetCode 104. Maximum Depth of Binary Tree
2016-10-21 09:07
357 查看
描述
求树的深度解决
递归。/** * 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 1 + max(maxDepth(root -> right), maxDepth(root -> left)); } };
相关文章推荐
- LeetCode 111. Minimum Depth of Binary Tree
- LeetCode 111. Minimum Depth of Binary Tree
- Leetcode 654. Maximum Binary Tree 最大二叉树 解题报告
- LeetCode 104. Maximum Depth of Binary Tree
- LeetCode——Binary Tree Inorder Traversal
- LeetCode——111. Minimum Depth of Binary Tree
- 【LeetCode】111.Minimum Depth of Binary Tree
- leetcode:104. Maximum Depth of Binary Tree
- LeetCode 111. Minimum Depth of Binary Tree
- [leetcode]111. Minimum Depth of Binary Tree
- 【LeetCode】111. Minimum Depth of Binary Tree
- LeetCode 543. Diameter of Binary Tree
- [Leetcode] Binary tree--653. Two Sum IV
- leetcode 每日一题 111. Minimum Depth of Binary Tree
- Leetcode Everyday: 104. Maximum Depth of Binary Tree
- leetcode-104. Maximum Depth of Binary Tree
- [勇者闯LeetCode] 104. Maximum Depth of Binary Tree
- LCP104 LeetCode 104. Maximum Depth of Binary Tree
- [leetcode] 543. Diameter of Binary Tree
- [leetcode: Python] 111. Minimum Depth of Binary Tree