```
class NumArray {
public:
NumArray(vector<int> &nums) {
res.push_back(nums[0]);
for(int i = 1;i < nums.size();i++)
res.push_back(res[i-1]+nums[i]);
}
int sumRange(int i, int j) {
int r;
if(i == 0)
r = res[j];
else
r = res[j]-res[i-1];
return r;
}
private:
vector<int> res;
};
```

// Your NumArray object will be instantiated and called as such:

// NumArray numArray(nums);

// numArray.sumRange(0, 1);

// numArray.sumRange(1, 2);