303. Range Sum Query - Immutable
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.
Example:
Note:
You may assume that the array does not change.
There are many calls to sumRange function.
解题要点:
标准DP题,声明一个dp数组,把nums里的数累计加到dp直到最后一位。需要返回sumRange时,直接调用dp[j + 1] - dp[i] 即可。
Last updated
Was this helpful?