树、递归————二叉树的最大深度

 1 /**
 2  * Definition for a binary tree node.
 3  * struct TreeNode {
 4  *     int val;
 5  *     TreeNode *left;
 6  *     TreeNode *right;
 7  *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 8  * };
 9  */
10 class Solution {
11 public:
12     int maxDepth(TreeNode* root) {
13         int maxdepth=0;
14         if(root==NULL) return 0;//递归基本情况分析
15         else{
16             maxdepth = max(maxDepth(root->left),maxDepth(root->right));//递归
17             return maxdepth+1;
18         }
19     }
20 };
原文地址:https://www.cnblogs.com/pacino12134/p/11062950.html