-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1488_Avoid_Flood_in_The_City.txt
More file actions
33 lines (33 loc) · 1.02 KB
/
1488_Avoid_Flood_in_The_City.txt
File metadata and controls
33 lines (33 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution {
public:
vector<int> avoidFlood(vector<int>& rains) {
unordered_set<int> vlakes;
vector<int> vresult(rains.size());
set<int> dryDays;
map<int,int> lastFillDay;
for(int i = 0; i < rains.size(); i++){
int lake = rains[i];
if(lake != 0){
if(vlakes.count(lake)){
auto it = dryDays.lower_bound(lastFillDay[lake]);
if(it == dryDays.end()){
return {};
}
int dryday = *it;
dryDays.erase(it);
vresult[dryday] = lake;
}
vlakes.insert(lake);
lastFillDay[lake] = i;
vresult[i] = -1;
} else {
dryDays.insert(i);
vresult[i] = 1;
}
}
for(auto &item : vresult){
if(item == 0) item = 1;
}
return vresult;
}
};