二叉树节点间的最大距离问题
来源:互联网 发布:商家给淘宝消费积分 编辑:程序博客网 时间:2024/06/06 17:40
/** * Created by lxw, liwei4939@126.com on 2017/10/30. * 二叉树节点间的最大距离问题 */public class BTMaxDistance { public class Node{ int value; Node left; Node right; public Node(int data){ this.value = data; } } public int MaxDistance(Node head){ int[] record = new int[1]; return posOrder(head, record); } public int posOrder(Node head, int[] record){ if(head == null){ record[0] = 0; return 0; } int lMax = posOrder(head.left, record); int MaxfromLeft = record[0]; int rMax = posOrder(head.right, record); int MaxfromRight = record[0]; record[0] = Math.max(MaxfromLeft, MaxfromRight) + 1; int curNodeMax = MaxfromLeft + MaxfromRight + 1; return Math.max(Math.max(lMax, rMax), curNodeMax); }}
阅读全文
0 0
- 二叉树问题---二叉树节点间的最大距离
- 二叉树节点间的最大距离问题
- 二叉树节点间的最大距离问题
- 二叉树节点间的最大距离问题
- 二叉树节点间的最大距离
- 求二叉树节点的最大距离
- 二叉树中节点的最大距离
- 二叉树中节点的最大距离
- 二叉树中节点的最大距离
- 二叉树中节点的最大距离
- 二叉树中节点的最大距离
- 二叉树中节点的最大距离
- 求二叉树节点的最大距离
- 二叉树中节点的最大距离
- 二叉树中节点的最大距离
- 二叉树中节点的最大距离
- 求二叉树节点的最大距离
- 二叉树中节点的最大距离
- Ubuntu下搭建python开发环境
- spark中可以影响到结果partition个数的操作
- 网页爬虫小程序
- 习题3.1
- linux top命令查看内存及多核CPU的使用讲述
- 二叉树节点间的最大距离问题
- python笔记007--内存管理
- python 使用sys.stdin和fileinput读入标准输入
- c语言学习笔记-作业-素数
- data
- Python Imaging Library: ImageSequence Module(图像序列模块)
- JNI so库加载流程之System.loadLibrary流程分析
- 1001. 害死人不偿命的(3n+1)猜想 (15)C语言
- centos系统图形界面和命令行模式切换