My 3ms clean Java DP solution may help u


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

Log in to reply
 

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