题目描述
blablabla
样例
blablabla
算法1
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int Depth(TreeNode* root) {
if (!root) return 0;
int left=Depth(root->left);
int right=Depth(root->right);
return max(left,right)+1;
}
int treeDepth(TreeNode* root) {
return Depth(root);
}
};