在下面的图中,求[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. hdu1263 水果(结构体排序)

    Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样J ...

  2. springMVC之数据传递

    在前面介绍过从controller中向页面中传数据,可以通过HttpServletRequest进行setAttribute可以将数据放入request中.并且可以在jsp页面使用el表达式获取数据. ...

  3. Ext JS4百强应用: 用grid.plugin.CellEditing做高级查询 --第10强

    Ext JS4,用grid.plugin.CellEditing做高级查询: 写了90%,界面出来了,小兴奋就贴出来,还有细节要调整,基本能用. 代码: Ext.define('chenghao.ad ...

  4. 框架基础:ajax设计方案(三)---集成ajax上传技术

    之前发布了ajax的通用解决方案,核心的ajax发布请求,以及集成了轮询.这次去外国网站逛逛,然后发现了ajax level2的上传文件,所以就有了把ajax的上传文件集成进去的想法,ajax方案的l ...

  5. JS的运算问题……

    在公司实习期间,发现了一个JS很奇怪的问题. 今天在这里来探讨一下 第一个问题 在生活中或者其他语言中一般相加是这样的:0.1+0.2=0.3; 但在JS中却是这样:0.1+0.2=0.3000000 ...

  6. CI Weekly #11 | 微服务场景下的自动化测试与持续部署

    又一周过去了,最近我们的工程师正在搞一个"大事情" --「[flow.ci](http://flow.ci/?utm_source=bokeyuan&utm_medium= ...

  7. PHP里文件的查找方式及写法

    PHP里说的文件包括:文件和目录1.用filetype方法加路径("./11.txt")是判断文件类型 //var_dump(filetype("./11.txt&quo ...

  8. java加解密

    换工作中,把以前学的知识,整理整理.能否得到一份好的薪资且满意的工作,然后赢取白富美,走向人生的巅峰,就靠它了.哈哈. 对称加密:DES, AES DES (数据加密算法) : 明文按64位进行分组, ...

  9. 鼠标形状css样式

    鼠标形状css样式 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  10. const 那点事儿

    修饰变量时 const char 与 char const 是等价的,例如 const char a = 'a'; char const a = 'a'; 表示变量a不能再被赋予其他值. 到指针时情况 ...