My simple c++ solution


  • 0
    K
    class NumArray {
    public:
    vector<int>myvector;
    NumArray(vector<int> &nums) {
        myvector.resize(nums.size()+1);
        myvector[0]=0;
        for(int i=1;i<nums.size()+1;i++)
        {
            myvector[i]=myvector[i-1]+nums[i-1];
        }
    }
    
    int sumRange(int i, int j) {
        return myvector[j+1]-myvector[i];
    }
    

    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.