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. angular2 pipe实现搜索结果中的搜索关键字高亮

    效果图如下 1.声明一个pipe import {Pipe, Injectable, PipeTransform} from '@angular/core';import { DomSanitizer ...

  2. TensorFlow函数:tf.reduce_sum

    tf.reduce_sum 函数 reduce_sum ( input_tensor , axis = None , keep_dims = False , name = None , reducti ...

  3. oracle密码过期的修改

    ALTER USER 用户名 IDENTIFIED BY 密码 ;

  4. React Native 继续学习

    下一个项目公司也打算使用react native.大致看了下原型设计,写几个小demo先试试水.特此记录下. 1.微信及朋友圈分享.QQ及朋友圈分享,微博分享,微信支付,支付宝支付. 2.导航条渐隐 ...

  5. web(七)css的语法规则、注释

    css的语法规则:特殊的css语法标识. !important:当使用多种方式设定标签样式时,设定样式渲染的应用优先权,声明在取值之后. .important { color: red !import ...

  6. Django请求流程图

    Django请求流程图

  7. php 多线程

    windows下安装php真正的多线程扩展pthreads教程 http://www.thinkphp.cn/topic/22676.html PHP 安装 Pthreads (解决 class Th ...

  8. Python Json & Pickle模块

    用于序列化的两个模块 Json,用于字符串 和 python数据类型间进行转换 Pickle,用于python特有的类型 和 python的数据类型间进行转换 Json模块提供了四个功能:dumps. ...

  9. 安装包安装npm

    在阿里云机器上centos7安装npm可以直接yum安装,然后基于镜像的时候安装不了,直接使用安装包安装,记录一下: 官网下载地址:https://nodejs.org/en/download/ #! ...

  10. Fabric实例

    Fabric的官网  http://fabric-chs.readthedocs.io/zh_CN/chs/index.html 参考<Python自动化运维 技术与最佳实践>   1:查 ...