JZ38 二叉树的深度 本文最后更新于:2022年4月9日 中午 Solution 123456789101112131415161718/*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 == nullptr) return 0; int leftDepth = TreeDepth(pRoot->left); int rightDepth = TreeDepth(pRoot->right); return max(leftDepth, rightDepth) + 1; }}; algo 二叉树 nowcoder 本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处! JZ39 平衡二叉树 上一篇 JZ37 数字在升序数组中出现的次数 下一篇 Please enable JavaScript to view the comments powered by Valine.