其他分享
首页 > 其他分享> > 二叉树的深度

二叉树的深度

作者:互联网

参考  https://blog.csdn.net/hyqsong/article/details/50807183

 

1.非递归 

采用层次遍历的方法,类似bfs的解法

递归

 

1  int TreeDepth(TreeNode* pRoot)
2     {
3         if (pRoot == NULL)
4             return 0;
5         else
6             return max(1 + TreeDepth(pRoot->left), 1 + TreeDepth(pRoot->right));
7 
8     }
9  

 

标签:return,tem,int,pRoot,len,二叉树,TreeDepth,深度
来源: https://www.cnblogs.com/kwaitfort/p/10468968.html