class NumArray {
public:
vector<int> sums;
NumArray(vector<int>& nums) {
sums.resize(nums.size()+1);
sums[0] = 0;
for(int i = 0; i < nums.size(); i++)
{
sums[i+1] = sums[i] + nums[i];
}
}
int sumRange(int left, int right) {
return sums[right+1]-sums[left];
}
};
/**
* Your NumArray object will be instantiated and called as such:
* NumArray* obj = new NumArray(nums);
* int param_1 = obj->sumRange(left,right);
*/
leetcode每日一题第六十六天
最新推荐文章于 2024-10-31 16:16:13 发布