剑指offer-39.二叉树的深度
来源:互联网 发布:激光洗眉机网络假货 编辑:程序博客网 时间:2024/06/03 15:53
/** * 求二叉树的深度 * 递归:二叉树的深度等于左右子树的深度的最大值+1 * 参考后序遍历 */ public int treeDepth(TreeNode root) { if(root == null) return 0; int leftDepth = treeDepth(root.left); int rightDepth = treeDepth(root.right); return leftDepth > rightDepth ? leftDepth+1 : rightDepth+1; }
/** * 记录二叉树中每条路径 * 思路:仿照前序遍历 * @param args */ public void getAllPaths(TreeNode root){ if(root == null) return; path.add(root.val); if(root.left == null && root.right == null){ result.add(new ArrayList<>(path)); } getAllPaths(root.left); getAllPaths(root.right); path.remove(path.size()-1); }
阅读全文
0 0
- 剑指offer 39.二叉树的深度
- 剑指offer-39.二叉树的深度
- 剑指offer: 二叉树的深度(树)
- 剑指Offer之二叉树的深度
- 剑指offer--二叉树的深度
- 剑指offer之二叉树的深度
- 剑指Offer之 - 二叉树的深度
- 剑指offer-39 二叉树的深度
- 剑指offer 39 - 二叉树的深度
- 《剑指offer》二叉树的深度
- 剑指 offer:二叉树的深度
- 剑指offer—二叉树的深度
- 剑指Offer--二叉树的深度
- 剑指offer-二叉树的深度
- 剑指offer:求二叉树的深度
- 剑指offer 38 二叉树的深度
- 剑指offer 二叉树的深度
- 剑指Offer--039-二叉树的深度
- 闲记
- typedef
- python 安装superset:error: Setup script exited with error: command 'gcc' failed with exit status 1
- 小白如何成长为优秀的系统设计专家?
- 7.2—查找—Sear Insert Position
- 剑指offer-39.二叉树的深度
- 关于日间夜间模式切换的一种实用方法
- 7.3—查找—Sear a 2D Matrix
- 框架就快开源了
- 使用若要打开fc-list,您需要安装X11
- wamp环境配置phpstorm的断点调试功能。和打开debug会出现waiting for incoming connetcion with ide key 17173的问题
- Struts2-01
- 深入理解Java:注解(Annotation)--注解处理器
- 8.1—暴力枚举法—Subsets