Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 2 Next »

前缀和

LC 303. Range Sum Query - Immutable 区域和检索 - 数组不可变

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

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 二维区域和检索 - 矩阵不可变

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

双指针数组

LC 88. Merge Sorted Array 合并两个有序数组

https://leetcode.com/problems/merge-sorted-array/

& More

  • No labels