leetcode 303.区域和检索-数组不可变
1.题目要求:
2.题目代码:
class NumArray {
public:
vector<int> array;
NumArray(vector<int>& nums) {
array = nums;
}
int sumRange(int left, int right) {
int sum = 0;
while(left <= right){
sum += array[left];
left++;
}
return sum;
}
};
/**
* Your NumArray object will be instantiated and called as such:
* NumArray* obj = new NumArray(nums);
* int param_1 = obj->sumRange(left,right);
*/