370.区间加法
一、直接法
class Solution {
public:
vector<int> getModifiedArray(int length, vector<vector<int>>& updates) {
vector<int> res(length);
for (auto u : updates) {
for (int i = u[0]; i <= u[1]; i++) {
res[i] += u[2];
}
}
return res;
}
};二、差分数组
最后更新于