最后更新

二刷

08-Jan-2017

一刷忘了什么时候做的,只是觉得这几个题挺好的,一步一步手动构建线段树,最终理解了这个数据结构,并且后面有利用的地方。

其实重要的3个东西题目已经提供了:

  1. left < right return null
  2. left == right return root
  3. (left, mid), (mid+1, right)
public class Solution {

     public SegmentTreeNode build(int start, int end) {
if (start > end) return null;
SegmentTreeNode tempRoot = new SegmentTreeNode(start, end);
if (start == end) return tempRoot;
int mid = start + (end - start) / 2;
tempRoot.left = build(start, mid);
tempRoot.right = build(mid + 1, end);
return tempRoot;
} }

201. Segment Tree Build的更多相关文章

  1. [LintCode] Segment Tree Build II 建立线段树之二

    The structure of Segment Tree is a binary tree which each node has two attributes startand end denot ...

  2. Segment Tree Build I & II

    Segment Tree Build I The structure of Segment Tree is a binary tree which each node has two attribut ...

  3. [LintCode] Segment Tree Build 建立线段树

    The structure of Segment Tree is a binary tree which each node has two attributes start and end deno ...

  4. Lintcode: Segment Tree Build

    The structure of Segment Tree is a binary tree which each node has two attributes start and end deno ...

  5. 439. Segment Tree Build II

    最后更新 08-Jan-2017 开始介绍线段树的主要作用了,可以快速在区间查找极值,我猜是这样的..... 一个NODE的最大值取决于它左边和右边最大值里大 按个,所以,所以什么?对了,我们该用po ...

  6. Lintcode: Segment Tree Modify

    For a Maximum Segment Tree, which each node has an extra value max to store the maximum value in thi ...

  7. Lintcode247 Segment Tree Query II solution 题解

    [题目描述] For an array, we can build a Segment Tree for it, each node stores an extra attribute count t ...

  8. Segment Tree Query I & II

    Segment Tree Query I For an integer array (index from 0 to n-1, where n is the size of this array), ...

  9. Lintcode: Segment Tree Query II

    For an array, we can build a SegmentTree for it, each node stores an extra attribute count to denote ...

随机推荐

  1. 获取本机外网ip和内网ip

    获取本机外网ip //获取本机的公网IP public static string GetIP() { string tempip = ""; try { WebRequest r ...

  2. Linux busybox mount -a fstab

    /*********************************************************************** * Linux busybox mount -a fs ...

  3. RubyWin32Api Win32OLE

    #ruby提供了多种运行外部程序的方法 #1.%x %x不需要使用引号包含. #2. system方法 #3.exec类似system但是会中断当前的代码执行 #system和exec不能捕获执行程序 ...

  4. Android 打勾显示输入的密码

    main.xml: <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:and ...

  5. 【Mongo】Linux安装MongoDB

    呵呵哒,每天都是小惊喜. 一 下载 https://www.mongodb.org/downloads可进行下载,根据需要选择合适的版本和操作系统 二 上传服务器 1 上传服务器路径并解压 2 创建数 ...

  6. bzoj3884: 上帝与集合的正确用法 欧拉降幂公式

    欧拉降幂公式:http://blog.csdn.net/acdreamers/article/details/8236942 糖教题解处:http://blog.csdn.net/skywalkert ...

  7. 【LeetCode 221】Maximal Square

    Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ret ...

  8. PHP 系统命令函数

    function execute($cmd) { $res = ''; if ($cmd) { if(function_exists('system')) { @ob_start(); @system ...

  9. 【跟我一起学Python吧】python学习摘要

    开始靖,怒推一篇文章:码农平时应该注意的办公室礼节 学习一门脚本语言是很有必要的,当我们在开发一些简单,快速程序时,脚本语言便有了用武之地,而且还很給力.根据python的介绍,python是一门很简 ...

  10. C语言的代码内存布局

    由以下3个部分组成: 1)BSS 段 BSS段(bss segment)通常是指用来存放程序中未初始化的全局变量的一块内存区域.BSS是英文Block Started by Symbol的简称.BSS ...