leetcode1026
public class Solution
{
Stack<int> S = new Stack<int>();
int maxValue = ;
public void Trace(TreeNode root)
{
if (root != null)
{
S.Push(root.val);
if (root.left != null)
{
Trace(root.left);
}
if (root.right != null)
{
Trace(root.right);
}
if (root.left == null && root.right == null)
{ var ary = S.ToArray().Reverse().ToList();
var len = ary.Count();
for (var i = ; i < len; i++)
{
for (int j = i + ; j < len; j++)
{
maxValue = Math.Max(maxValue, Math.Abs(ary[i] - ary[j]));
}
//Console.WriteLine(a);
}
//Console.WriteLine(maxValue);
}
S.Pop();
}
}
public int MaxAncestorDiff(TreeNode root)
{
Trace(root);
return maxValue;
}
}
leetcode1026的更多相关文章
- [Swift]LeetCode1026. 节点与其祖先之间的最大差值 | Maximum Difference Between Node and Ancestor
Given the root of a binary tree, find the maximum value V for which there exists different nodes A a ...
随机推荐
- thinkphp获取后台所有控制器和action
<?phpnamespace Admin\Controller;use Think\Controller;class AuthorController extends PublicControl ...
- springBoot的数据库操作
一:操作数据库起步 1.Spring-Data-Jpa JPA定义了对象持久化的标准. 目前实现了有Hibernate,TopLink 2.pom添加依赖 <dependency> < ...
- TX锁处理
实际处理后,在测试环境中模拟还原TX锁,及处理. 本篇博客目录: 1.TX锁模拟实际环境 2.登陆数据库,查询相关信息 3.确认锁源头,kill进程释放资源 一.TX锁模拟 sess_1 SQL> ...
- LVS DR模式搭建、keepalived+lvs
1.LVS DR模式搭建 条件: 即三台机器,在同一内网. 编辑脚本文件:/usr/local/sbin/lvs_dr.sh #! /bin/bashecho 1 > /proc/sys/net ...
- 查看Linux磁盘空间
df -hl 查看磁盘剩余空间 df -h 查看每个根路径的分区大小 du -sh [目录名] 返回该目录的大小 du -sm [文件夹] 返回该文件夹总M数 du -h [目录名] 查看指定文件夹下 ...
- tcpdump抓包常用参数和用法
tcpdump 与wireshark Wireshark(以前是ethereal)是Windows下非常简单易用的抓包工具.但在Linux下很难找到一个好用的图形化抓包工具.还好有Tcpdump.我们 ...
- Flutter 知识点
Flutter:一个移动应用开发框架,它使用 Dart.C++.Skia 开发,对外提供了完全不依赖系统平台的 Widget 的能力,只通过自绘图形的方式工作,具有极其优秀的跨平台性.目前已经支持了 ...
- 数组中只出现一次的数字(java实现)
问题描述 一个整型数组里除了两个数字之外,其他的数字都出现了偶数次.请写程序找出这两个只出现一次的数字. 解题思路 如果数组中只有一个数字出现奇数次,则将数组中所有的数字做异或可得该数字. 数组中有两 ...
- freemarker语法介绍及其入门教程实例
# freemarker语法介绍及其入门教程实例 # ## FreeMarker标签使用 #####一.FreeMarker模板文件主要有4个部分组成</br>#### 1.文本,直接输 ...
- C#中Button.DialogResult属性
窗体中的某个按钮,如果设置了DialogResult(不是设置为None),当窗体是通过ShowDialog方法显示的时候 则不必设置任何响应函数,单击按钮也可窗体.然后,该窗体的DialogResu ...