303. Range Sum Query
来源:互联网 发布:深度睡眠软件 编辑:程序博客网 时间:2024/05/16 12:55
题目:
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.
Example:
Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRange(0, 5) -> -3
Note:
- You may assume that the array does not change.
- There are many calls to sumRange function.
代码:
class NumArray {
public:
vector<int> newnums;
NumArray(vector<int> nums) {
for(int i =0;i<nums.size();i++)
{
newnums.push_back(nums[i]);
}
}
int sumRange(int i, int j) {
int result = 0;
for(int k = i;k<=j;k++)
{
result = result + newnums[k];
}
return result;
}
};
/**
* Your NumArray object will be instantiated and called as such:
* NumArray obj = new NumArray(nums);
* int param_1 = obj.sumRange(i,j);
*/
0 0
- 303. Range Sum Query
- 303. Range Sum Query
- 303. Range Sum Query
- 303. Range Sum Query
- 303. Range Sum Query
- 303. Range Sum Query
- 303. Range Sum Query
- 303. Range Sum Query
- 303. Range Sum Query
- 303. Range Sum Query
- 303. Range Sum Query
- 303. Range Sum Query
- 303. Range Sum Query
- 303. Range Sum Query
- 303. Range Sum Query
- 303. Range Sum Query
- 303. Range Sum Query
- 303. Range Sum Query
- 构造函数与析构函数
- Night ride
- PHP反射API汇总(转自低调小一博客)
- 基于Hadoop的云计算平台搭建(伪分布式)
- VALN TAG超经典解释
- 303. Range Sum Query
- VisualVM 实现JVM内存监控
- 详解LSTM
- “浏览器设置从上次停下的地方继续,但是电脑重启打开后还是主页”问题的解决办法
- javascript自定义右键菜单并屏蔽默认右键菜单【原创】
- TypeScript设计模式之门面、适配器
- PLSQL执行SQL文件。
- Visual Studio 20周年软件趋势随想
- leetcode每日一题:(7)Reverse Integer