java, 2 ms, beat 98%


  • 1
    T

    The key is "count++" and "for(int i:nums)"

    public class NumArray {
    int[] left;
    
        public NumArray(int[] nums) {
           left = new int[nums.length+1];
           int count=0;
           for(int i:nums){
               left[count +1] = left[count++] + i;
           }
        }
    
        public int sumRange(int i, int j) {
            return left[j+1] - left[i];
        }
    }
    

  • 0

    Genius, good job.


Log in to reply
 

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