Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Autosaved

...

https://leetcode.com/problems/range-sum-query-immutable/

Code Block
languagego
type NumArray struct {
    sums []int
}


func Constructor(nums []int) NumArray {
    sums := make([]int, len(nums))
    sums[0] = nums[0]
    for i := 1; i < len(nums); i++ {
        sums[i] = sums[i-1] + nums[i]
    }
    return NumArray{sums}
}


func (this *NumArray) SumRange(left int, right int) int {
    if left == 0 {
        return this.sums[right] 
    }
    
    return this.sums[right] - this.sums[left-1]
}


/**
 * Your NumArray object will be instantiated and called as such:
 * obj := Constructor(nums);
 * param_1 := obj.SumRange(left,right);
 */

LC 304. Range Sum Query 2D - Immutable 二维区域和检索 - 矩阵不可变

...