2. 二叉树的深度
題目描述
輸入一棵二叉樹,求該樹的深度。從根結點到葉結點依次經過的結點(含根、葉結點)形成樹的一條路徑,最長路徑的長度為樹的深度。
/* struct TreeNode {int val;struct TreeNode *left;struct TreeNode *right;TreeNode(int x) :val(x), left(NULL), right(NULL) {} };*/ class Solution { public:int TreeDepth(TreeNode* pRoot){if(!pRoot) return 0;return max(TreeDepth(pRoot->left), TreeDepth(pRoot->right)) + 1;} };?
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
- 上一篇: 在成都欢乐谷耍一天要好多钱
- 下一篇: 极米z6x灯泡能换吗