力扣2251.花期内花的数目
-
差分
- 1e9数据范围优雅的写法
cpp
class Solution {
public:
vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& persons) {
map<int,int> mp;
for(auto &it:flowers) mp[it[0]] ++ , mp[it[1] + 1] --;
for(auto x:persons) mp[x];
int tot = 0;
for(auto &[x,y] : mp)
y = (tot += y);
for(auto &x:persons)
x = mp[x];
return persons;
}
};