- /**
- * Definition of TreeNode:
- * class TreeNode {
- * public:
- * int val;
- * TreeNode *left, *right;
- * TreeNode(int val) {
- * this->val = val;
- * this->left = this->right = NULL;
- * }
- * }
- */
- class Solution {
- public:
- /**
- * @param root: The root of binary tree.
- * @return: An integer
- */
- int maxDepth(TreeNode * root) {
- if (!root) return 0;
- return 1 + max(maxDepth(root->left), maxDepth(root->right));
- }
- };
来源: http://www.bubuko.com/infodetail-2766785.html