当前位置:网站首页>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];
}
}
边栏推荐
- SQL cultivation manual from scratch - practical part
- 2021上海市赛-B-排序后dp
- 2019陕西省省赛J-位运算+贪心
- 2021 Shanghai match-h-two point answer
- PAT甲级题目目录
- Submarine cable detector tss350 (I)
- Notes on inputview and inputaccessoryview of uitextfield
- Geogle Colab笔记1--运行Geogle云端硬盘上的.py文件
- MySQL—用户和权限管控
- How to solve the login problem after the 30 day experience period of visual stuido2019
猜你喜欢

Graph theory and concept

ML - 自然语言处理 - 自然语言处理简介

ML - 语音 - 高级语音模型

Application of C language array in Sanzi chess -- prototype of Queen n problem

Ml speech depth neural network model

ML - 自然语言处理 - 基础知识

matlab 如何保存所有运行后的数据

Reflection - Notes

Idea eye care settings

Take you to create your first C program (recommended Collection)
随机推荐
CF685B-求有根树每颗子树的重心
2021上海市赛-B-排序后dp
Pat grade a 1153 decode registration card of PAT (25 points)
2016 CCPC network trial c-change root DP good question
Idea - click the file code to automatically synchronize with the directory
PageHelper does not take effect, and SQL does not automatically add limit
Pytorch学习笔记-刘二老师RNN高级篇-代码注释及结果
Singleton mode 3-- singleton mode
In depth: micro and macro tasks
Cf365-e - Mishka and divisors, number theory +dp
LeetCode - 379 电话目录管理系统(设计)
2021上海市赛-H-二分答案
BPSK调制系统MATLAB仿真实现(1)
如何解决跨域问题
Word 样式模板复制到另一文档
2021江苏省赛A. Array-线段树,维护值域,欧拉降幂
ML - 自然语言处理 - 基础知识
matlab 优化工具 manopt 安装
CF888G-巧妙字典树+暴力分治(异或最小生成树)
matlab 如何保存所有运行后的数据