当前位置:网站首页>Leetcode - 303 area and retrieval - array immutable (design prefix and array)
Leetcode - 303 area and retrieval - array immutable (design prefix and array)
2022-07-25 15:40:00 【Cute at the age of three @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];
}
}
边栏推荐
- 2016 CCPC network trial c-change root DP good question
- MySQL - Summary of common SQL statements
- Binary complement
- Singleton mode 3-- singleton mode
- 2021上海市赛-H-二分答案
- Pytorch学习笔记-刘二老师RNN高级篇-代码注释及结果
- C # fine sorting knowledge points 12 exception handling (recommended Collection)
- LeetCode - 303 区域和检索 - 数组不可变 (设计 前缀和数组)
- How to realize page inclusion
- The difference between mouseover and mouseenter
猜你喜欢

Brain racking CPU context switching

JVM—类加载器和双亲委派模型

Node learning

LeetCode - 380 O(1) 时间插入、删除和获取随机元素 (设计 哈希表+数组)

MySQL—用户和权限管控

Pat grade a 1152 Google recruitment (20 points)

解决vender-base.66c6fc1c0b393478adf7.js:6 TypeError: Cannot read property ‘validate‘ of undefined问题

JVM knowledge brain map sharing

Window system black window redis error 20creating server TCP listening socket *: 6379: listen: unknown error19-07-28

Gary marcus: learning a language is more difficult than you think
随机推荐
matlab 如何保存所有运行后的数据
Idea - click the file code to automatically synchronize with the directory
LeetCode - 232 用栈实现队列 (设计 双栈实现队列)
小波变换--dwt2 与wavedec2
Node learning
Wechat applet
CVPR 2022 | 网络中批处理归一化估计偏移的深入研究
Binary complement
Cf365-e - Mishka and divisors, number theory +dp
mouseover和mouseenter的区别
哪里有搭建flink cdc抽mysql数的demo?
MySQL - Summary of common SQL statements
数据系统分区设计 - 分区再平衡(rebalancing)
BPSK调制系统MATLAB仿真实现(1)
Distributed principle - what is a distributed system
PAT甲级1151 LCA in a Binary Tree (30 分)
How to realize page inclusion
Are you ready to break away from the "involution circle"?
CF566A-贪心+字典树
2021HNCPC-E-差分,思维