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 ...
随机推荐
- Visual Studio Code--开发大大们都在用的编辑器
老公推荐的炒鸡nb的编辑器...说让我看起来像个假大神(微笑脸) 如何用VSCode练习python呢,还有VSCode有哪些常用的功能和快捷键呢?我会持续更新中... 1. 先来换个喜欢的颜色主题吧 ...
- nodejs -- require , exports , module
1. require , exports . -------------------------- 文件: 1) index.js //两种方式都可以: var forExports = requir ...
- phpcms 路由配置
这是一个由apache多站点配置引发的"血案",本以为是本地多站点配置的问题,结果找了半天没找到相关配置,最后还是问的大腿,同时也了解一些关于c盘hosts文件的映射作用以及使用 ...
- Floodlight1.2+Mininet的安装及使用
直接转载的大神的,亲测Ubuntu16.04版本没问题 https://www.sdnlab.com/19189.html
- PHP发送POST请求
方式一:cURL $url = "localhost/test/post/service.php"; $data = array("a"=>"网 ...
- spring-boot入门总结
1.org.springframework.web.bind.annotation不存在 错误的pom.xml <dependency> <groupId>org.spring ...
- 【mysql】工具使用
mysql之workbench如何只导出(insert语句)数据 MySQL 编码:utf8 与 utf8mb4,utf8mb4_unicode_ci 与 utf8mb4_general_ci htt ...
- edgedb 强大的对象关系数据库
edgedb 是一个强大的对象关系数据库,构建在pg 之上. 包含的特性: 严格的强类型模式; 强大而富有表现力的查询语言; 丰富的标准库; 内置支持模式迁移; 本机GraphQL支持. 数据模型 从 ...
- day 41 标准文档流 浮动
一.标准文档流 什么是标准文档流 宏观的将,我们的web页面和ps等设计软件有本质的区别,web 网页的制作,是个“流”,从上而下 ,像 “织毛衣”.而设计软件 ,想往哪里画东西,就去哪里画 标准文档 ...
- 使用sshpass方式实现ssh自动登录
1:sshpass下载地址(用yum安装不了) https://sourceforge.net/projects/sshpass/files/ or wget http://sourcef ...