303. Range Sum Query - Immutable
2016-07-09 10:45
459 查看
Given an integer array nums, find the sum of the elements between indices
i and j (i ≤ j), inclusive.
Example:
Note:
You may assume that the array does not change.
There are many calls to sumRange function.
Subscribe to see which companies asked this question
i and j (i ≤ j), inclusive.
Example:
Given nums = [-2, 0, 3, -5, 2, -1] sumRange(0, 2) -> 1 sumRange(2, 5) -> -1 sumRange(0, 5) -> -3
Note:
You may assume that the array does not change.
There are many calls to sumRange function.
Subscribe to see which companies asked this question
class NumArray { public: vector <int> v1={0}; NumArray(vector<int> &nums) { for(int i=0;i<nums.size();++i) v1.push_back(nums[i]+v1.back()); } int sumRange(int i, int j) { return v1[j+1]-v1[i]; } }; // Your NumArray object will be instantiated and called as such: // NumArray numArray(nums); // numArray.sumRange(0, 1); // numArray.sumRange(1, 2);
相关文章推荐
- UEFI启动的windows下安装Ubuntu双系统(绝对可行)
- CodeForces 678C The Values You Can Make (3维DP)
- iOS开发出现 CUICatalog: Invalid asset name supplied: (null)
- HDU 4893 Wow! Such Sequence! (线段树单点更新+区间更新+区间查询+二分)
- 使用GPUImage实现视频滤镜
- poj 2299 Ultra QuickSort 树状数组+离散化
- String StringBuffer和StringBuilder
- HDU 5301 Buildings (乱搞)
- Codeforces 689D Friends and Subsequences(RMQ+二分)
- [leetcode]62. Unique Paths
- 2016 UESTC Training for Math G - 完美点集 解方程
- 2016 UESTC Training for Math F - 粗心的谭爷 素数线性筛法的推广
- 2016 UESTC Training for Math D - 熄灯啦! 讨论
- 2016 UESTC Training for Math A - 谭爷的黑暗沙拉 组合学
- There is no getter for property named 'xxx' in 'class com.xuezhixin.mls.web.model.yyy
- Segment Tree Query I & II
- Segment Tree Build I & II
- EasyUI Pagination 分页的两种做法小结
- 从用户行为到用户界面的最后一道门:分析与计算
- MySQL Packet for query is too large