力扣1943.描述绘画结果
-
map存差分
- 遍历每组数据 加入res
-
class Solution {public:vector<vector<long long>> splitPainting(vector<vector<int>>& segments) {map<int,long long> mp;for(auto t:segments){mp[t[0]] += t[2];mp[t[1]] -= t[2];}vector<vector<long long>> res;long long st=0,sum=0;for(auto t:mp){if(sum != 0) res.push_back({st,t.first,sum});sum += t.second;st = t.first;}return res;}};