给一个dfs的题解
二叉树的深度
http://www.nowcoder.com/questionTerminal/435fb86331474282a3499955f0a41e8b
void dfs(TreeNode* pRoot,int& res,int&dep){ ++dep; if(pRoot->left==nullptr&&pRoot->right==nullptr){res=max(res,dep);--dep;return;} if(pRoot->left) dfs(pRoot->left,res,dep); if(pRoot->right)dfs(pRoot->right,res,dep); --dep; } int TreeDepth(TreeNode* pRoot) { int res=0,dep=0; if(pRoot==nullptr)return res; dfs(pRoot,res,dep); return res; }