# [303. Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable/description/)
# 思路
用一个数组sums记录和，sums[i]代表nums[0]到nums[i]的和，那么sumRange(i, j)就应该等于sum[i] - sum[i-1], 注意单独判断i得0时。    
注意这种面向对象的代码风格。
# C++
```C++
class NumArray {
private:
    vector<int> sums;
public:
    NumArray(vector<int> nums) {
        int tmp = 0;
        for(int num: nums) {
            tmp += num;
            sums.push_back(tmp);
        }
    }
    
    int sumRange(int i, int j) {
        if(i == 0) return sums[j];
        else return sums[j] - sums[i - 1];
    }
};
```
