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 ...
随机推荐
- Linux基础知识_Shell编程笔记
以下是一些 常用功能 , 基于 centos 6.5 x64 # cp /etc/localtime /etc/localtime.org # rm /etc/localtime # ln -s /u ...
- java面向对象编程(四)--类变量、类方法
1.什么是类变量? 类变量是该类的所有对象共享的变量,任何一个该类的对象去访问它时,取到的都是相同的值,同样任何一个该类的对象去修改它时,修改的也是同一个变量. 如何定义类变量? 定义语法: ...
- 自动化测试-18.selenium之bugFree代码注释
#encoding=utf-8 import xlrd,time,os from xlutils.copy import copy from selenium import webdriver def ...
- RabbitMq入门以及使用教程
祭出原帖:https://blog.csdn.net/lyhkmm/article/details/78772919 原文转载:http://blog.csdn.net/whycold/article ...
- Flume架构以及应用介绍
在具体介绍本文内容之前,先给大家看一下Hadoop业务的整体开发流程: 从Hadoop的业务开发流程图中可以看出,在大数据的业务处理过程中,对于数据的采集是十分重要的一步,也是不可避免的一步,从而引 ...
- Angular + Websocket
Angular使用RxJS,它本质上是一个反应式扩展的javascript实现.这是一个使用可观察序列组成异步和基于事件的程序的库,非常适合使用WebSockets. 简而言之,RxJS允许我们从we ...
- linux kernel driver debug
1. print printk(): never pr_debug(): always good dev_dbg(): prefered when you have a struct device o ...
- 20165308 2017-2018-2 《Java程序设计》课程总结
20165308 2017-2018-2 <Java程序设计>课程总结 一.每周作业及实验报告链接汇总 我期待的师生关系 学习基础和c语言调查 Linux 安装及学习 第一周学习总结 第二 ...
- ILBC 运行时 (ILBC Runtime) 架构
本文是 VMBC / D# 项目 的 系列文章, 有关 VMBC / D# , 见 <我发起并创立了一个 VMBC 的 子项目 D#>(以下简称 <D#>) https:// ...
- CentOS7 上学习使用docker
一.CentOS7(64)上安装和使用docker的笔记. 1. 增加docker用户 sudo groupadd docker sudo useradd -g docker docker 2. 增加 ...