Beats 99.23%


  • 0
    K

    Self explanatory :)

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

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.