public class NumArray {
int[] nums = null;
public NumArray(int[] nums) {
this.nums = nums;
}
public int sumRange(int i, int j) {
if(i < 0 || j >= nums.length){
return 0;
}
else{
int sum = 0;
for(int k = i; k <= j; k++){
sum += nums[k];
}
return sum;
}
}
}
/**
* Your NumArray object will be instantiated and called as such:
* NumArray obj = new NumArray(nums);
* int param_1 = obj.sumRange(i,j);
*/
leetcode[Range Sum Query - Immutable]//待整理多种解法
最新推荐文章于 2021-03-01 14:53:00 发布