题目:
class Solution {
public:
void traversal(TreeNode* cur, int& max, int depth){ //max用来记录最长路径长度,depth记录当前路径长度
if(!cur) return;
depth++;
if(depth>max) max = depth;
traversal(cur->left, max, depth);
traversal(cur->right, max, depth);
}
int maxDepth(TreeNode* root) {
int max = 0;
if(!root) return max;
traversal(root, max, 0);
return max;
}
};
标签:return,cur,Offer,55,max,traversal,int,depth,二叉树
From: https://www.cnblogs.com/fly-smart/p/17642361.html