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 ...
随机推荐
- mysql varchar存储最大
utf-8的汉字 3个字节,varchar()括号中的数字是可存储的最大字符数,但是总和不超过65535个字节,这是行的size限制的,除以3差不多21800多,算上其他列等信息,如果用最大的话设置2 ...
- AC Challenge(状压dp)
ACM-ICPC 2018 南京赛区网络预赛E: 题目链接https://www.jisuanke.com/contest/1555?view=challenges Dlsj is competing ...
- REST easy with kbmMW #24 使用kbmMW实现JSON/XML/YAML转换成对象
你想过没有,把一个给定的xml或json生成一个Delphi类,并通过这个类完成对xml或json的读写操作吗? 不管有没有,现在kbmMW为我们实现了,看下面这行代码: var s:string; ...
- 剑指Offer 34. 第一个只出现一次的字符 (字符串)
题目描述 在一个字符串(0<=字符串长度<=10000,全部由字母组成)中找到第一个只出现一次的字符,并返回它的位置, 如果没有则返回 -1(需要区分大小写). 题目地址 https:// ...
- spring boot 之 spring task(定时任务)
cron:通过表达式来配置任务执行时间cron表达式详解 一个cron表达式有至少6个(也可能7个)有空格分隔的时间元素.按顺序依次为: 秒(0~59)分钟(0~59)3 小时(0~23)4 天(0 ...
- Ubuntu16.04中pip无法更新升级,采用源码方式安装
1.从pip官网下载最新版 https://pypi.org/project/pip/#files 2.ubuntu中创建文件位置,我的放在一下路径,之后进行解压 3.解压后进入pip的文件夹,在执行 ...
- django 增加自定义权限的一个博客,讲的很详细
来自 https://www.cnblogs.com/huangxm/p/5770735.html
- 第四节《Git检出》
使用过Git的朋友们都谁知道git reset可以达到重置效果,不知道的小伙伴们可以看下上一篇博客,重置命令的一个用途就是修改引用的游标指向,实际上在执行重置命令的时候没有使用任何参数对所要重置的分支 ...
- asp.net 动态更改 Request.Header
public class Dev_Sim: IHttpModule { public void Init(HttpApplication app) { app.BeginRequest += dele ...
- Hystrix 学习使用
说明: 每次调用创建一个新的HystrixCommand,把依赖调用封装在run()方法中 执行execute()/queue做同步或异步调用 请求接收后,会先看是否存在缓存数据,如果存在,则不会继续 ...