标签:剑指offer item 深度 style dep 题目 描述 node tree
1 class Solution { 2 public: 3 int TreeDepth(TreeNode* pRoot) 4 { 5 if (pRoot == nullptr)return 0; 6 //深度优先遍历 7 DFS(pRoot, 1); 8 return maxLevel; 9 } 10 11 private: 12 int maxLevel = -1; 13 void DFS(TreeNode *pRoot, int level) 14 { 15 if (pRoot == nullptr)return; 16 maxLevel = maxLevel > level ? maxLevel : level; 17 DFS(pRoot->left, level + 1); 18 DFS(pRoot->right, level + 1); 19 } 20 };
标签:剑指offer item 深度 style dep 题目 描述 node tree
原文地址:https://www.cnblogs.com/zzw1024/p/11706992.html