当前位置:网站首页>LeetCode - 303 区域和检索 - 数组不可变 (设计 前缀和数组)
LeetCode - 303 区域和检索 - 数组不可变 (设计 前缀和数组)
2022-07-25 15:32:00 【三岁就很萌@D】



class NumArray {
private int[] preSum;
public NumArray(int[] nums) {
int n = nums.length;
preSum = new int[n+1];
for(int i = 0; i < n;i++)
preSum[i+1] = preSum[i] + nums[i];
}
public int sumRange(int left, int right) {
return preSum[right+1] - preSum[left];
}
}
边栏推荐
猜你喜欢

Use cpolar to build a business website (how to buy a domain name)

谷歌云盘如何关联Google Colab

小波变换--dwt2 与wavedec2

matlab--CVX优化工具包安装

使用cpolar建立一个商业网站(如何购买域名)

GAMES101复习:变换

MySQL transactions and mvcc

Cf888g clever dictionary tree + violent divide and conquer (XOR minimum spanning tree)

4PAM在高斯信道与瑞利信道下的基带仿真系统实验

图论及概念
随机推荐
Understanding the difference between wait() and sleep()
Pytorch学习笔记--常用函数总结2
ML - natural language processing - Key Technologies
window系统黑窗口redis报错20Creating Server TCP listening socket *:6379: listen: Unknown error19-07-28
Local cache --ehcache
Cf566a greed + dictionary tree
MySQL—用户和权限管控
你准备好脱离“内卷化怪圈”了吗?
Hdu3873 shortest path with dependency (topological sorting)
Icpc2021 Kunming m-violence + chairman tree
IOS interview questions
Games101 review: 3D transformation
MySQL优化总结二
2019陕西省省赛J-位运算+贪心
ML - Speech - advanced speech model
2019 Shaanxi provincial competition j-bit operation + greed
C#精挑整理知识要点9 集合2(建议收藏)
Graph theory and concept
MySQL optimization summary II
JVM knowledge brain map sharing