当前位置:网站首页>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];
}
}
边栏推荐
- Geogle Colab笔记1--运行Geogle云端硬盘上的.py文件
- MATLAB 如何生产随机复序列
- Application of C language array in Sanzi chess -- prototype of Queen n problem
- CF685B-求有根树每颗子树的重心
- Qtime定义(手工废物利用简单好看)
- Cf750f1 thinking DP
- 2021hncpc-e-difference, thinking
- Xcode added mobileprovision certificate file error: Xcode encoded an error
- Notes on inputview and inputaccessoryview of uitextfield
- 带你创建你的第一个C#程序(建议收藏)
猜你喜欢

Idea eye care settings

Get the ask code corresponding to the key pressed by the keyboard

matlab--CVX优化工具包安装

Pytorch学习笔记--Pytorch常用函数总结1

p4552-差分

LeetCode - 379 电话目录管理系统(设计)

为什么PrepareStatement性能更好更安全?

No tracked branch configured for branch xxx or the branch doesn‘t exist. To make your branch trac

Box avoiding mouse

ML - 自然语言处理 - 自然语言处理简介
随机推荐
C#精挑整理知识要点11 委托和事件(建议收藏)
2021上海市赛-D-卡特兰数变种,dp
谷歌云盘如何关联Google Colab
LeetCode - 622 设计循环队列 (设计)
The development summary of the function of fast playback of audio and video in any format on the web page.
Flex 布局
GAMES101复习:变换
PageHelper does not take effect, and SQL does not automatically add limit
MySQL transactions and mvcc
Phased summary of the research and development of the "library management system -" borrowing and returning "module
Get the ask code corresponding to the key pressed by the keyboard
C#精挑整理知识要点9 集合2(建议收藏)
MySQL优化总结二
Idea eye care settings
UIDocumentInteractionController UIDocumentPickerViewController
带你详细认识JS基础语法(建议收藏)
CF750F1-思维dp
HDU3873-有依赖的最短路(拓扑排序)
JVM knowledge brain map sharing
Pat grade a 1152 Google recruitment (20 points)