...
https://leetcode.com/problems/range-sum-query-immutable/
Code Block | ||
---|---|---|
| ||
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 二维区域和检索 - 矩阵不可变
...