landscapemi的博客

# leetcode: Segment Tree:Range Sum Query - Mutable(307)

https://leetcode.com/problems/range-sum-query-mutable/

class NumArray {
public:
NumArray(vector<int> &nums) {
num.resize(nums.size() + 1);
bit.resize(nums.size() + 1);
for (int i = 0; i < nums.size(); ++i) {
update(i, nums[i]);
}
}
void update(int i, int val) {
int diff = val - num[i + 1];
for (int j = i + 1; j < num.size(); j += (j&-j)) {
bit[j] += diff;
}
num[i + 1] = val;
}
int sumRange(int i, int j) {
return getSum(j + 1) - getSum(i);
}
int getSum(int i) {
int res = 0;
for (int j = i; j > 0; j -= (j&-j)) {
res += bit[j];
}
return res;
}

private:
vector<int> num;
vector<int> bit;
};

#### (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

#### [LeetCode308]Range Sum Query 2D - Mutable

2015-11-29 07:27:19

#### 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 308. Range Sum Query 2D - Mutable（二维区间求和）

2016-04-20 10:31:57

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

2015-11-20 14:58:33

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

2016-01-21 01:06:07

#### leetcode 303: Range Sum Query - Immutable

2015-11-10 17:47:28