@@ -32,20 +32,20 @@ numArray.sumRange(0, 5); // return (-2) + 0 + 3 + (-5) + 2 + (-1) = -3
32
32
```
33
33
34
34
###Constraints
35
- - ` 1 <= nums.length <=10000 `
36
- - ` -100000 <= nums[i] <=100000 `
35
+ - ` 1 <= nums.length <=10^4 `
36
+ - ` -10^5 <= nums[i] <=10^5 `
37
37
- ` 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 ` .
39
39
40
40
##Intuition
41
41
###Solution 2
42
42
Directly returning the sum of the array elements can pass the tests, but if the test case is more stringent, it will fail.
43
43
So we still need to learn a more efficient solution.
44
44
45
45
###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] ` .
49
49
50
50
##Complexity
51
51
* Time:` O(n) ` .