您的位置:首页 > 产品设计 > UI/UE

leetcode[Range Sum Query - Immutable]//待整理多种解法

2017-07-10 10:48 417 查看
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);
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: