Here is O(n) compute time version without precompute

```
public class NumArray {
int[] nums;
public NumArray(int[] nums) {
this.nums=nums;
}
public int sumRange(int i, int j) {
int sum = 0;
for (int k=i;k<=j;k++){
sum = sum+nums[k];
}
return sum;
}
}
```

Here is O(1) compute time version with precompute

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