版权声明:噗噗个噗~~~ https://blog.csdn.net/Puyar_/article/details/85268060
[编程题] maximum-depth-of-binary-tree
时间限制:1秒
空间限制:32768K
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.
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int maxDepth(TreeNode *root) {
if(root==NULL)return 0;
else {
int t1=maxDepth(root->left);
int t2=maxDepth(root->right);
return 1+max(t1,t2);
}
}
};