c++ 3 lines


  • 0
    B
    class NumArray {
    public:
        vector<int>data;
        NumArray(vector<int> &nums) {
            data.push_back(0);
            for(auto e : nums) data.push_back(data.back()+e);
        }
    
        int sumRange(int i, int j) {
            return data[j+1]-data[i];
        }
    };

Log in to reply
 

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