```
private final int[] sums;
public NumArray(final int[] nums) {
this.sums = new int[nums.length + 1];
for (int i = 0; i < nums.length; i++) {
sums[i + 1] = nums[i] + sums[i];
}
}
public int sumRange(final int i, final int j) {
return sums[j + 1] - sums[i];
}
```