# leetcode之Range Sum Query - Mutable

class NumArray(object):
def __init__(self, nums):
"""
:type nums: List[int]
"""
self.items = nums
self.sum1 = sum(self.items)

def update(self, i, val):
"""
:type i: int
:type val: int
:rtype: int
"""
self.sum1 = self.sum1 - self.items[i] + val
self.items[i] = val

def sumRange(self, i, j):
"""
sum of elements nums[i..j], inclusive.
:type i: int
:type j: int
:rtype: int
"""
a = 0
if j - i >= len(self.items) / 2:
return self.sum1 - sum(self.items[:i]) - sum(self.items[j + 1:])
else:
return sum(self.items[i: j + 1])

#### leetcode -- Range Sum Query - Mutable -- 重点，有线段树

2016-01-14 10:35:09

#### [leetcode] 308. Range Sum Query 2D - Mutable 解题报告

2016-03-22 09:17:18

#### (LeetCode 307) Range Sum Query - Mutable(树状数组讲解)

2016-04-17 15:45:04

#### [leetcode-307]Range Sum Query - Mutable(java)

2015-11-22 16:22:01

#### LeetCode（307） Range Sum Query - Mutable

2015-12-12 17:21:23

#### LeetCode 308. Range Sum Query 2D - Mutable（二维区间求和）

2016-04-20 10:31:57

#### LeetCode 307 Range Sum Query - Mutable（范围和查询-可变）

2016-06-29 12:37:14

#### 【矩阵子阵求和问题】 leetcode 308. Range Sum Query 2D - Mutable

2017-08-06 16:23:58

#### [LeetCode]Range Sum Query - Mutable

2015-11-20 14:58:33

#### leetcode笔记：Range Sum Query - Mutable

2016-01-21 01:06:07