First get the accumulated `sum[]`

and then for range `[i, j]`

, the sum is: `sum[j]`

- `sum[i-1]`

, but be careful of the corner case when `i`

equals to `0`

.

```
public class NumArray {
int[] sums;
public NumArray(int[] nums) {
sums = new int[nums.length];
// accumulate the sum from nums[0] to nums[i]
for (int i = 0; i < nums.length; i++)
sums[i] = nums[i] + ((i > 0) ? sums[i - 1] : 0);
}
public int sumRange(int i, int j) {
return (i == 0) ? sums[j] : sums[j] - sums[i - 1];
}
}
```