您好,欢迎来到华拓网。
搜索
您的当前位置:首页303. Range Sum Query - Immutable

303. Range Sum Query - Immutable

来源:华拓网

不是算法题,大概是考constructer的吧???

public class NumArray {
    int[] nums;
    
    public NumArray(int[] nums) {
        for(int i=1; i < nums.length; i++)
            nums[i] += nums[i-1];
        this.nums = nums;
    }

    public int sumRange(int i, int j) {
        if(i == 0)
            return nums[j];
        return nums[j] - nums[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);

Copyright © 2019- huatuo3.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务