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的更多相关文章

  1. [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 ...

随机推荐

  1. admin 后台

    https://segmentfault.com/a/1190000015835976#articleHeader3https://github.com/PanJiaChen/vue-element- ...

  2. Linux:CentOS 7系统的安装

    相信有看过我写的博文就知道我写的第一篇博文就是CentOS 7系统的安装,不过是在虚拟机中安装的,而且还是直接加载镜像文件进去的,不过这次我就通过PE来安装,来证实下PE是否可以用来安装Linux系统 ...

  3. # 学号 20175223 《Java程序设计》第3周学习总结

    学号 20175223 <Java程序设计>第3周学习总结 教材学习内容总结 第四章要点: 要点1:面向对象三个性质:封装性.继承.多态: 要点2:类:类声明.类体.成员变量.方法.类的U ...

  4. ios 中pickerView用法之国旗选择

    QRViewController控制器 // // QRViewController.m // #import "QRViewController.h" #import " ...

  5. java面向对象编程(三)--this

    看一段代码:(Demo112.java),先了解为什么要使用this. /* this的必要性 */ public class Demo112{ public static void main(Str ...

  6. Ansible 任务计时

    在 github 发现一个 Ansible 任务计时插件“ansible-profile”,安装这个插件后会显示 ansible-playbook 执行每一个任务所花费的时间.Github 地址: h ...

  7. Windows10 64位安装TensorFlow-GPU

    TensorFlow有GPU版和CPU版. GPU版需要CUDA和cuDNN支持,到链接:https://developer.nvidia.com/cuda-gpus 确认自己的显卡是否支持CUDA. ...

  8. 设计一款相册APP,代替系统自带的相册功能,列举主要功能

    分析:先分析原生相册的不足,用户需求痛点,然后描述下界面设计,并说明为什么用户要使用你的产品.       iOS系统手机,自带的相机有基础的拍照,基础的美颜效果.除了本地存储,还有icloud可以存 ...

  9. Atom选中多行操作

    没有用过sublime,但是有选取多行的需求 我有一个文本文件,前面几行都是文件夹路径,并且都是单个字母,我想删除路径,保存纯粹的子文件夹名称,这样可以上传谷歌翻译文档,写程序再写txt略显麻烦,直接 ...

  10. js调用app启动页

    第一步:添加js $(function () { var ua = window.navigator.userAgent.toLowerCase(); //微信 if(ua.match(/MicroM ...