利用深度优先搜索,递归+1
class Solution { public: int maxDepth(TreeNode* root) { if(root==NULL) { return 0; } return max(maxDepth(root->left),maxDepth(root->right))+1; } };
Maximum Depth of Binary Tree
原文:https://www.cnblogs.com/zhangdalao/p/14606909.html