JavaScript Solution


  • 2
    L
    function NumArray(nums) {
      this.sums = [];
      var sum = 0;
      for (var i = 0; i < nums.length; i++) {
        sum += nums[i];
        this.sums.push(sum);
      }
    }
    
    NumArray.prototype.sumRange = function(i, j) {
      return this.sums[j] - (i > 0 ? this.sums[i - 1] : 0);
    };

Log in to reply
 

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