Skip to content

Commit c1c5442

Browse files
committed
Updated 303-range-sum-query-immutable.md
1 parent 0835de8 commit c1c5442

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

en/1-1000/303-range-sum-query-immutable.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ numArray.sumRange(0, 5); // return (-2) + 0 + 3 + (-5) + 2 + (-1) = -3
3232
```
3333

3434
### Constraints
35-
- `1 <= nums.length <= 10000`
36-
- `-100000 <= nums[i] <= 100000`
35+
- `1 <= nums.length <= 10^4`
36+
- `-10^5 <= nums[i] <= 10^5`
3737
- `0 <= left <= right < nums.length`
38-
- At most `10000` calls will be made to `sumRange`.
38+
- At most `10^4` calls will be made to `sumRange`.
3939

4040
## Intuition
4141
### Solution 2
4242
Directly returning the sum of the array elements can pass the tests, but if the test case is more stringent, it will fail.
4343
So we still need to learn a more efficient solution.
4444

4545
### Solution 1: Prefix Sum
46-
* Use a new array `prefix_sums` to save the sum of the previous elements.
47-
* The first element of `prefix_sums` is `0` because the prefix sum **does not include the current element**.
48-
* To find the `sum` of the elements from index `left` to `right` (inclusive), just use `prefix_sums[right + 1] - prefix_sums[left]`.
46+
- Use a new array `prefix_sums` to save the sum of the previous elements.
47+
- The first element of `prefix_sums` is `0` because the prefix sum **does not include the current element**.
48+
- To find the `sum` of the elements from index `left` to `right` (inclusive), just use `prefix_sums[right + 1] - prefix_sums[left]`.
4949

5050
## Complexity
5151
* Time: `O(n)`.

0 commit comments

Comments
 (0)