
详细思路
dfs,需要root,求出该root树的最大深度
精确定义
dfs,参数root求出root树的最大深度,边界root空返回0,最后返回左右最大深度+1
class Solution { public: int maxDepth(TreeNode* root) { if(!root)return 0; return 1+max(maxDepth(root->left),maxDepth(root->right)); } };
浙公网安备 33010602011771号