s4553711
5/24/2017 - 3:38 PM

303.cpp

class NumArray {
public:
    vector<int> result;
    NumArray(vector<int> nums) {
        int tmp = 0;
        for (int i = 0; i < nums.size(); i++) {
            tmp += nums[i];
            result.push_back(tmp);
        }
    }
    
    int sumRange(int i, int j) {
        return result[j] - result[i - 1];
    }
};

/**
 * Your NumArray object will be instantiated and called as such:
 * NumArray obj = new NumArray(nums);
 * int param_1 = obj.sumRange(i,j);
 */