Total Accepted: 219677 Total Submissions: 427419 Difficulty: Easy Contributors: Admin Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 求二叉树的最大深度
解法:
class Solution {
public:
int maxDepth(TreeNode* root) {
if(!root)
return 0;
return 1+max(maxDepth(root->left),maxDepth(root->right));
}
};
转载请注明原文地址: https://ju.6miu.com/read-19049.html