Minimum Number of Buckets Required to Collect Rainwater from Houses LeetCode solution in C++

1
class Solution {
2
public:
3
int minimumBuckets(string street) {
4
unordered_map<int, int> mp;
5
int res = 0;
6
for (int i = 0; i < street.size(); i++) {
7
if (street[i] == 'H') {
8
if (mp[i + 1] > 0 or mp[i - 1] > 0) continue;
9
if (i + 1 < street.size() and street[i + 1] == '.') {
10
res++;
11
mp[i + 1]++;
12
continue;
13
}
14
if (i - 1 >= 0 and street[i - 1] == '.') {
15
res++;
16
continue;
17
}
18
return -1;
19
}
20
}
21
return res;
22
}
23
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0