# 题目
# 举例
下图二叉树的深度为4,最长路径为1-2-5-7.
# 思路(递归)
如果一个树只有一个节点,它的深度为1;
如果根节点只有左子树而没有右子树,那么树的深度应该是其左子树的深度+1;
如果根节点只有右子树而没有左子树,那么树的深度应该是其右子树的深度+1;
如果根节点既有左子树又有右子树,那么树的深度应该是左右字数深度的较大值+1.
# 代码
1 class Solution {
2 public:
3 int TreeDepth(TreeNode* pRoot)
4 {
5 if(pRoot == nullptr)
6 return 0;
7 int left = TreeDepth(pRoot->left);
8 int right = TreeDepth(pRoot->right);
9
10 return (left>right) ? (left+1) : (right+1);
11
12 }
13 };


