C++ 14 lines beats 100%!


  • 0
    Z
    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];
            }
            return vector<int>(res.begin(),res.begin()+length);
        }
    };
    

Log in to reply
 

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