labuladong / basic-challenge

200 stars 22 forks source link

已结束 #345

Closed labuladong closed 1 year ago

labuladong commented 1 year ago

本期打卡已结算完成。报名最新一期的打卡活动 点这里

AlanKang98 commented 1 year ago

https://leetcode.cn/problems/range-sum-query-immutable/solutions/2370533/qian-zhui-he-shu-zu-by-alank-usyd-2rwz/

dh0072 commented 1 year ago

Q303. Range Sum Query - Immutable https://leetcode.com/problems/range-sum-query-immutable/discuss/3854818/Java-prefix-solution

Q304. Range Sum Query 2D - Immutable https://leetcode.com/problems/range-sum-query-2d-immutable/discuss/3854827/Java-prefix-solution

ImmersiveAngela commented 1 year ago

303 区域和检索 - 数组不可变 https://leetcode.cn/problems/range-sum-query-immutable/solutions/2370602/qu-yu-he-jian-suo-shu-zu-bu-ke-bian-by-i-wt27/

ShaodongGu commented 1 year ago

Q303 https://leetcode.com/problems/range-sum-query-immutable/solutions/3854198/standard-prefix-sum/

zexianw12 commented 1 year ago

Q303 https://leetcode.cn/problems/range-sum-query-immutable/solutions/2370614/li-yong-qian-zhui-he-shi-xian-qiu-jie-by-pa7z/

6520874 commented 1 year ago

https://leetcode.cn/problems/range-sum-query-immutable/solutions/2370626/303-qu-yu-he-jian-suo-shu-zu-bu-ke-bian-asems/

GodisinHisHeaven commented 1 year ago

https://leetcode.com/problems/range-sum-query-2d-immutable/solutions/3855554/pre-sum-python-solution/

PINKDDDD commented 1 year ago

https://leetcode.com/problems/random-pick-with-weight/solutions/3855574/random-pick-with-weight/ https://leetcode.com/problems/range-sum-query-immutable/solutions/3855598/range-sum-query-immutable/

Sadwy commented 1 year ago

LC304. https://leetcode.com/problems/range-sum-query-2d-immutable/solutions/3855659/2d-prefix-sum/

Chao200 commented 1 year ago

303: https://leetcode.cn/problems/range-sum-query-immutable/solutions/2370700/solution303-qu-yu-he-jian-suo-shu-zu-bu-iw9o2/

304: https://leetcode.cn/problems/range-sum-query-2d-immutable/solutions/2370743/solution304-er-wei-qu-yu-he-jian-suo-ju-jeumg/

guabigwind commented 1 year ago

区域和检索 - 数组不可变: https://leetcode.cn/problems/range-sum-query-immutable/solutions/2370803/qu-yu-he-jian-suo-shu-zu-bu-ke-bian-by-g-o4yw/ 二维区域和检索 - 矩阵不可变: https://leetcode.cn/problems/range-sum-query-2d-immutable/solutions/2371056/er-wei-qu-yu-he-jian-suo-ju-zhen-bu-ke-b-j81j/

chen-huanxin commented 1 year ago

303:https://leetcode.cn/problems/range-sum-query-immutable/solutions/2370841/cpp-qian-zhui-he-fang-fa-303-qu-yu-he-ji-0zjm/ 304:https://leetcode.cn/problems/range-sum-query-2d-immutable/solutions/2370866/cpp-qian-zhui-he-fang-fa-304-er-wei-qu-y-5rth/

jojoss commented 1 year ago

[304. Range Sum Query 2D - Immutable] https://leetcode.com/problems/range-sum-query-2d-immutable/solutions/3855792/prefix-sum/

Bamoon622 commented 1 year ago

https://leetcode.com/problems/range-sum-query-immutable/solutions/3855491/using-prefix-sum-array/ https://leetcode.com/problems/range-sum-query-2d-immutable/solutions/3855803/dynamic-programming-solution/

macksonyli21826 commented 1 year ago

https://leetcode.cn/problems/range-sum-query-immutable/solutions/2370932/problem-303-qu-yu-he-jian-suo-shu-zu-bu-i11lp/

wusidong commented 1 year ago

https://leetcode.cn/problems/range-sum-query-immutable/solutions/2370941/qu-yu-he-jian-suo-shu-zu-bu-ke-bian-by-g-rltq/

CarolSSS commented 1 year ago

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

wangyin717 commented 1 year ago
  1. 区域和检索 - 数组不可变 https://leetcode.cn/problems/range-sum-query-immutable/solutions/2371105/303-qu-yu-he-jian-suo-shu-zu-bu-ke-bian-2o6by/
ghost commented 1 year ago

https://leetcode.cn/problems/range-sum-query-immutable/solutions/2371148/qian-xu-he-by-alan-aa-tvj9/ https://leetcode.cn/problems/range-sum-query-2d-immutable/solutions/2371204/er-wei-qian-zhui-he-by-alan-aa-xm75/

sdyin commented 1 year ago

303.区域和检索 https://leetcode.cn/problems/range-sum-query-immutable/solutions/2371195/303qu-yu-he-jian-suo-ti-jie-by-sdyin-80j0/

azDev120 commented 1 year ago

304: https://leetcode.com/problems/range-sum-query-2d-immutable/solutions/3856821/2d-prefix-sum-method-in-java/

Adrian0999 commented 1 year ago

https://leetcode.com/problems/range-sum-query-immutable/solutions/3856972/establish-a-new-array-to-speed-up-the-search-speed/

Catboss1999 commented 1 year ago

303.区域和检索: https://leetcode.cn/problems/range-sum-query-immutable/solutions/2371291/qian-zhui-he-by-cat-boss-bkuv/ 304.二位区域和检索: https://leetcode.cn/problems/range-sum-query-2d-immutable/solutions/2371340/er-wei-qian-zhui-he-by-cat-boss-nq05/

hxingjie commented 1 year ago

303.https://leetcode.cn/problems/range-sum-query-immutable/solutions/2371318/qu-yu-he-jian-suo-shu-zu-bu-ke-bian-by-b-rcxk/ 304.https://leetcode.cn/problems/range-sum-query-2d-immutable/solutions/2371381/er-wei-qu-yu-he-jian-suo-ju-zhen-bu-ke-b-g4dv/

javaSnacks commented 1 year ago

303.https://leetcode.cn/problems/range-sum-query-immutable/solutions/2371425/303-qu-yu-he-jian-suo-shu-zu-bu-ke-bian-9e3az/

txhj1996 commented 1 year ago

https://leetcode.cn/problems/range-sum-query-immutable/solution/qu-yu-he-jian-suo-yi-wei-shu-zu-by-6ifte-djsf/ https://leetcode.cn/problems/range-sum-query-2d-immutable/solution/er-wei-qu-yu-jian-suo-by-6ifted-vvrightj-n6cc/ https://leetcode.cn/problems/subarray-sum-equals-k/solution/he-wei-kde-zi-shu-zu-by-6ifted-vvrightj2-f1b6/

Abbyyuan01 commented 1 year ago

https://leetcode.cn/problems/range-sum-query-immutable/solutions/2371377/qian-zhui-he-jie-ti-by-abbyyuan01-akkt/ https://leetcode.cn/problems/range-sum-query-2d-immutable/solutions/2371498/er-wei-qian-zhui-he-by-abbyyuan01-smb7/

Susan19996 commented 1 year ago

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

Jingzhenzxz commented 1 year ago

https://leetcode.cn/problems/range-sum-query-immutable/solutions/2371679/qian-zhui-he-zhu-yi-java-yu-yan-ru-he-di-29lh/ 前缀和。注意 Java 语言如何定义数组,如何给数组赋值,构造方法没有返回值等。

class NumArray {
    // 初始化前缀和数组,注意初始化数组的写法
    private int[] preSum;

    public NumArray(int[] nums) {
        // 赋值的时候不用写 int[]
        preSum = new int[nums.length + 1];

        // 根据 nums 构造前缀和数组 preSum
        for (int i = 1; i < preSum.length; i++) {
            preSum[i] = preSum[i - 1] + nums[i - 1];
        }
        // 构造方法没有返回值
    }

    public int sumRange(int left, int right) {
        return preSum[right + 1] - preSum[left];
    }
}

/**
 * Your NumArray object will be instantiated and called as such:
 * NumArray obj = new NumArray(nums);
 * int param_1 = obj.sumRange(left,right);
 */
Reset0808 commented 1 year ago

https://leetcode.cn/problems/range-sum-query-immutable/solutions/2371768/qian-zhui-wen-ti-by-2ba4zmutle-xu6k/

KarlZhu-SE commented 1 year ago

https://leetcode.com/problems/range-sum-query-2d-immutable/solutions/3858249/prefix-sum-python3/

skyc26 commented 1 year ago

https://leetcode.cn/problems/range-sum-query-immutable/solutions/2371922/303-qu-yu-he-jian-suo-shu-zu-bu-ke-bian-6qgk4/

sukhfskehwefisfsenkfn commented 1 year ago

https://leetcode.cn/problems/range-sum-query-immutable/solutions/2371929/jie-jue-fang-fa-by-bao-tu-6-p69y/

lidebin11 commented 1 year ago

303.区域和检索 https://leetcode.cn/problems/range-sum-query-immutable/solutions/2372026/python-qian-zhui-he-si-xiang-by-icer5-1l0c/

jiuxi521 commented 1 year ago

https://leetcode.cn/problems/range-sum-query-immutable/solutions/2372049/yi-wei-shu-zu-qian-zhui-he-tao-lu-by-lea-q8q8/

KenanHuang commented 1 year ago

https://leetcode.cn/problems/range-sum-query-2d-immutable/solutions/2372118/nummatrix-by-qq540453543-zk7r/

xueyanyun commented 1 year ago

https://leetcode.cn/problems/range-sum-query-immutable/solutions/2372175/qu-yu-he-jian-suo-shu-zu-bu-ke-bian-by-z-eecx/

Rayden-Xu commented 1 year ago

详细理解下标index的问题,很容易写错 1.构造presum数据 核心思想 原数组的 presum[i-1] 累加值 + nums[i-1] 原数组值 一起作为下一个前缀和 因为错位1,presum要比 nums长1位,留了一个0,所以index要i-1来进行 前一个的累加+原数组的 pre [2] = pre[1]+nums[1]

def __init__(self, nums: List[int]):
    presum =[0]* len((nums)+1) # 构造为0数组
    for i in range(1,len(presum)) # 错一位进行开始
    presum[i] = presum[i-1]+ nums[i-1]

def sumRange(self, left: int, right: int) -> int:
    return self.presum[right+1] - self.presum[left]

2.定范围查找 思维转化,将原数组nums left累加到right的加法问题转换为dual的相减问题, 例如 cumlative [3~7] = 3+4+5+6+7 Dual:从1+到7的presum[7+1] - presum[3] 注意这里我们因为做了偏移presum的第一个数字是0,index是0,所以是presum[8]才能是01234567

作者:RaydenX 链接:https://leetcode.cn/problems/range-sum-query-immutable/solutions/2372216/qian-zhui-he-lei-ji-lei-ji-chai-de-si-we-93pu/

Cathy830 commented 1 year ago

https://leetcode.com/problems/range-sum-query-immutable/solutions/3860296/range-sum-query-in-java-using-prefix-sum/

cs-gavin-huang commented 1 year ago

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

guaZong commented 1 year ago

https://leetcode.cn/problems/range-sum-query-immutable/solutions/2372279/qian-zhui-he-ti-jie-by-gua-xi-xi-8-3hq5/

uhu-11 commented 1 year ago

https://leetcode.cn/problems/range-sum-query-immutable/solutions/2372575/qu-yu-he-jian-suo-shu-zu-bu-ke-bian-qian-7aqz/

yayideng commented 1 year ago

https://leetcode.cn/problems/range-sum-query-2d-immutable/solutions/2372605/qian-zhui-he-by-7aughing-i3habhasyh-xq4j/

ljrirene commented 1 year ago

https://leetcode.com/problems/range-sum-query-immutable/solutions/3861159/one-d-arrary-prefix-sum/

vanessacz commented 1 year ago
  1. Range Sum Query - Immutable https://leetcode.com/problems/range-sum-query-immutable/solutions/3861676/java-constant-time-solution-pre-sum-array/
Pikalili commented 1 year ago

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

SuperChaoChao666 commented 1 year ago

前缀和计算数组的区间 https://leetcode.cn/problems/range-sum-query-immutable/solutions/2372947/qian-zhui-he-ji-suan-shu-zu-de-qu-jian-z-rzm4/

tonyzhu163 commented 1 year ago

https://leetcode.com/problems/range-sum-query-immutable/discuss/3918178/LC-303-Python

LexieZhou commented 1 year ago

https://leetcode.com/problems/range-sum-query-immutable/solutions/3862567/java-easy-solution/

DannyT70 commented 1 year ago

https://leetcode.cn/problems/range-sum-query-immutable/solutions/2373312/qian-zhui-he-1-by-sleepy-shawffi-pnt3/