求二叉树中节点的最大距离 即二叉树中相距最远的两个节点之间的距离
来源:互联网 发布:北大青鸟学软件编程 编辑:程序博客网 时间:2024/05/22 17:06
<span style="font-size:18px;"> public static int height(TreeNode t) // postcondition: returns height of tree with root t { if (t == null) { return 0; } else { return 1+Math.max(height(t.left),height(t.right)); } } public static int getMaxdis(TreeNode tree){ // post: return Max distance of tree if (tree == null) return 0; int lheight = height(tree.left); int rheight = height(tree.right); int ldiameter = getMaxdis(tree.left); int rdiameter = getMaxdis(tree.right); return Math.max(lheight + rheight,Math.max(ldiameter,rdiameter)); }</span>
0 0
- 求二叉树中节点的最大距离 即二叉树中相距最远的两个节点之间的距离
- 二叉树中相距最远的两个节点之间的距离
- 二叉树中相距最远的两个节点之间的距离
- 二叉树中相距最远的两个节点之间的距离
- 求二叉树中最远的两个节点的距离
- 求二叉树中最远的两个节点的距离
- ~求二叉树中最远的两个节点的距离~
- 求二叉树中最远的两个节点的距离
- 求二叉树中两个节点最远的距离
- 二叉树系列——二叉树的最大距离(即相距最远的两个叶子节点,编程之美,百度面试题)
- Java实现:在二叉树中,求距离最远的两个节点的距离
- 求一颗二叉树中最远的两个节点的距离
- 二叉树中最远两个节点的距离
- 二叉树中任意两个节点之间的最大距离
- 求二叉树中两个节点的最大距离
- 算法:求二叉树中两个节点的最大距离
- 二叉树系列---求二叉树中两个节点之间的最大距离
- 二叉树的两个节点之间最远的距离
- 完美解决IE6浏览器下不兼容position:fixed固定定位
- C# 中串口通信 serialport1.DataReceived 函数无法触发或者出发延时等等问题解决方法
- List Control控件
- 回不到过去
- NYOJ 492 King (状态压缩)
- 求二叉树中节点的最大距离 即二叉树中相距最远的两个节点之间的距离
- WebGoat 前期使用心得
- 在C++中使用TinyXML2解析xml
- poj 3667 最长空白段+查询最左连续段
- POJ 3067 Japan 树状数组求逆序对
- Redis源码分析(十)--- testhelp.h小型测试框架和redis-check-aof.c日志检测
- 中国目前O2O市场无非就是糯米、美团、大众点评为代表的BAT在角逐
- 【python 基础教程】第一章 基础知识
- Linux+Apache安装生成配置SSL证书