LintCode: Maximum Depth of Binary Tree

C++

 1 /**
 2  * Definition of TreeNode:
 3  * class TreeNode {
 4  * public:
 5  *     int val;
 6  *     TreeNode *left, *right;
 7  *     TreeNode(int val) {
 8  *         this->val = val;
 9  *         this->left = this->right = NULL;
10  *     }
11  * }
12  */
13 class Solution {
14 public:
15     /**
16      * @param root: The root of binary tree.
17      * @return: An integer
18      */
19     int maxDepth(TreeNode *root) {
20         // write your code here
21         if (root == NULL) {
22             return 0;
23         }
24         return max(maxDepth(root->left), maxDepth(root->right)) + 1;
25     }
26 };
原文地址:https://www.cnblogs.com/CheeseZH/p/5012506.html