LeetCode p303 Range Sum Query - Immutable 题解
1.题目:
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.
Example:
Given nums = [-2, 0, 3, -5, 2, -1]
sumRange(0, 2) -> 1
sumRange(2, 5) -> -1
sumRange(0, 5) -> -3
题意:
输出数组某一段的累加和。
2.解题思路:
累加 做差
3.代码
1 |
|