Leetcode 370 Solution
This article provides solution to leetcode question 370 (range-addition)
Access this page by simply typing in "lcs 370" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/range-addition
Solution
class Solution {
public:
vector<int> getModifiedArray(int length, vector<vector<int>>& updates) {
vector<int> a(length + 1);
for (auto update : updates)
{
a[update[0]] += update[2];
a[update[1] + 1] -= update[2];
}
vector<int> res(length);
int curr = 0;
for (int i = 0; i < length; i++)
{
curr += a[i];
res[i] = curr;
}
return res;
}
};