感觉我们是困了。。。
public class NumArray {
int [] sum = null;
public NumArray(int[] nums) {
sum = new int[nums.length];
for (int i = 0; i < nums.length; i++) {
//sum[i] = sum[i] + nums[i];
if (i > 0) {
sum[i] = sum[i - 1] + nums[i];
} else {
sum[i] = nums[i];
}
}
}
public int sumRange(int i, int j) {
//return sum[j] - sum[i];
if (i == 0)
return sum[j];
else
return sum[j] - sum[i - 1];
}
}
// Your NumArray object will be instantiated and called as such:
// NumArray numArray = new NumArray(nums);
// numArray.sumRange(0, 1);
// numArray.sumRange(1, 2);