在下面的图中,求[0,0]和[1,1]区间元素和,

对于[0,0] start =0 ,end = 0, 查到root = 4 [0-1]的节点,mid = 0, 此时mid > end-1,表示要查找的范围完全落到了4的左边节点,只递归左边

对于[1,1] start =1 ,end = 1, 查到root = 4 [0-1]的节点,mid = 0, 此时mid <start,表示要查找的范围完全落到了4的右边节点,只递归左边

对于[1,5],start = 1,end = 5,查到root = 36 [0-5]的节点,mid = 2,没有超出所求和区间[1,5],因此左右都要递归,由于root的左节点代表的区间为[0,mid],root右区间代表的区间为[mid+1],和所求和区间[1,5]合并 代码为 sum(root->left, start, mid)+return sum(root->right, mid+1, end)

线段树解决leetcode307. Range Sum Query - Mutable的更多相关文章

  1. [Leetcode Week16]Range Sum Query - Mutable

    Range Sum Query - Mutable 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/range-sum-query-mutable/de ...

  2. 【刷题-LeetCode】307. Range Sum Query - Mutable

    Range Sum Query - Mutable Given an integer array nums, find the sum of the elements between indices ...

  3. [LeetCode] Range Sum Query - Mutable 区域和检索 - 可变

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  4. [LeetCode] 307. Range Sum Query - Mutable 区域和检索 - 可变

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  5. LeetCode - 307. Range Sum Query - Mutable

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  6. leetcode笔记:Range Sum Query - Mutable

    一. 题目描写叙述 Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), ...

  7. 307. Range Sum Query - Mutable

    题目: Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclu ...

  8. [LeetCode] 307. Range Sum Query - Mutable 解题思路

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  9. [LeetCode] Range Sum Query - Mutable 题解

    题目 题目 思路 一看就是单点更新和区间求和,故用线段树做. 一开始没搞清楚,题目给定的i是从0开始还是从1开始,还以为是从1开始,导致后面把下标都改掉了,还有用区间更新的代码去实现单点更新,虽然两者 ...

随机推荐

  1. HDOJ 1755 - A Number Puzzle 排列数字凑同余,状态压缩DP

    dp [ x ] [ y ] [ z ] 表示二进制y所表示的组合对应的之和mod x余数为z的最小数... 如可用的数字为 1 2 3 4...那么 dp [ 7 ] [ 15 ] [ 2 ] = ...

  2. 【未来畅想】未来的电信通讯行业,账号密码将取代sim卡

    今天看到一条新闻,是关于LG模块化的手机,LG将手机电池模块化了,很多人一片叫好,但是我认为模块化手机无法成为未来的趋势,原因如下:模块化必然要增加手机的卡口.插口增,意味着体积也大大增加,手机正因为 ...

  3. 用linux 命令 执行ci框架的方法

    最近要跑一个数据量比较大的脚本,刚开始在浏览器页面访问发行nginx 5.4 超时, 又不想去修改nginx的连接时间,只能在服务器执行了, 执行方法:进入到ci 的根目录:#php index.ph ...

  4. Singleton Pattern(单例模式)

    1.简介 单例模式,顾名思义,即在整个系统中,类的实例对象只有一个. 单例模式具有以下特点: 单例类只能有一个实例 单例类必须自己创建自己的唯一实例 单例类必须给所有其他对象提供这一实例 2.实现 其 ...

  5. Linux CentOS 7 YUM 安裝 MySQL 5.7

    MySQL YUM 源:http://dev.mysql.com/downloads/repo/yum/ # 下載源 $ wget http://dev.mysql.com/get/mysql57-c ...

  6. python 数据清洗之字符串处理

    在数据分析中,特别是文本分析中,字符处理需要耗费极大的精力, 因而了解字符处理对于数据分析而言,也是一项很重要的能力. 字符串处理方法 首先我们先了解下都有哪些基础方法 首先我们了解下字符串的拆分sp ...

  7. Java中的修饰符

    -----------------------------------------------01----------------------------------------------- 类,方 ...

  8. UVa 1395 Slim Span

    问题:给出一个n结点的图,求最大边与最小边差值最小的生成树 my code: #include <iostream> #include <cstdio> #include &l ...

  9. ArrayList、HashSet、HashTable、List、Dictionary的区别

    在C#中,数组由于是固定长度的,所以常常不能满足我们开发的需求. 由于这种限制不方便,所以出现了ArrayList. ArrayList.List<T> ArrayList是可变长数组,你 ...

  10. Windows 下 Apache HTTP Server 与 Tomcat 的整合

    整合准备: 1.Apache HTTP Server(下文用Apache简称) 2.Tomcat 7或8 3.mod_jk.so (tomcat-connectors)-这个文件是用来链接http s ...