307 Range Sum Query - Mutable
1. Question
Given an integer arraynums, find the sum of the elements between indicesiandj(i≤j), inclusive.
The update(i, val) function modifies nums by updating the element at index i to val.
Example:
Note:
The array is only modifiable by the update function.
You may assume the number of calls to update and sumRange function is distributed evenly.
2. Implementation
(1) Binary Index Tree
3. Time & Space Complexity
Binary Indexed Tree: 时间复杂度: Binary Indexed Tree构造O(NlogN), update(logN), sumRange(logN), 空间复杂度O(N)
Last updated