C++ 8 line with 95ms beats 100%


  • 1
    Y

    class Solution {
    public:
    vector<int> getModifiedArray(int length, vector<vector<int>>& updates) {
    vector<int> res(length+1, 0);
    for(auto& u : updates) {
    res[u[0]] += u[2];
    res[u[1]+1] -= u[2];
    }
    for(int i = 1; i <= length; i++) { res[i] += res[i-1]; }
    res.pop_back();
    return res;
    }
    };


Log in to reply
 

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