当前位置:网站首页>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];
}
}
边栏推荐
猜你喜欢
随机推荐
p4552-差分
Games101 review: Transformation
Get the ask code corresponding to the key pressed by the keyboard
LeetCode - 379 电话目录管理系统(设计)
Flex layout
二进制补码
Word 样式模板复制到另一文档
LeetCode - 622 设计循环队列 (设计)
SVD奇异值分解推导及应用与信号恢复
2016CCPC网络选拔赛C-换根dp好题
2019陕西省省赛J-位运算+贪心
组件化和模块化
Distributed principle - what is a distributed system
LeetCode - 303 区域和检索 - 数组不可变 (设计 前缀和数组)
MySQL优化总结二
哪里有搭建flink cdc抽mysql数的demo?
带你创建你的第一个C#程序(建议收藏)
MySQL—常用SQL语句整理总结
对this对象的理解
How to solve cross domain problems









