Simple and Easy Solution


  • 2
    K

    class NumArray {

    vector<int> mat;
    

    public:

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

    };


Log in to reply
 

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