剑指offer-38-二叉树深度
二叉树的深度
http://www.nowcoder.com/questionTerminal/435fb86331474282a3499955f0a41e8b
思路
- 递归,比较简单
- 遍历,堆栈或者层序遍历
代码
public class Solution {
public int TreeDepth(TreeNode root) {
if(root==null){return 0;}
return 1+Math.max(TreeDepth(root.left),TreeDepth(root.right));
}
} 剑指offer与数据结构 文章被收录于专栏
本专栏包括剑指offer题目和一些刷题用的数据结构,单调栈,树状数组,差分数组,后面还会更新红黑树等较为复杂的数据结构
查看12道真题和解析