Skip to content

Commit bb21e48

Browse files
add 2086
1 parent 053daf7 commit bb21e48

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2086|[Minimum Number of Buckets Required to Collect Rainwater from Houses](https://leetcode.com/problems/minimum-number-of-buckets-required-to-collect-rainwater-from-houses/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2086.java) ||Medium||
1112
|2085|[Count Common Words With One Occurrence](https://leetcode.com/problems/count-common-words-with-one-occurrence/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2085.java) ||Easy||
1213
|2080|[Range Frequency Queries](https://leetcode.com/problems/range-frequency-queries/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2080.java) ||Medium|Array, Binary Search|
1314
|2079|[Watering Plants](https://leetcode.com/problems/watering-plants/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2079.java) ||Medium||
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _2086 {
4+
public static class Solution1 {
5+
public int minimumBuckets(String street) {
6+
int minBuckets = 0;
7+
int[] buckets = new int[street.length()];
8+
for (int i = 0; i < street.length(); i++) {
9+
if (street.charAt(i) == 'H') {
10+
if (i + 1 < street.length() && street.charAt(i + 1) == '.') {
11+
if (i - 1 >= 0 && buckets[i - 1] == 1) {
12+
continue;
13+
}
14+
buckets[i + 1] = 1;
15+
minBuckets++;
16+
} else if (i + 1 < street.length() && street.charAt(i + 1) == 'H') {
17+
if (i - 1 < 0) {
18+
return -1;
19+
} else if (i - 1 >= 0 && street.charAt(i - 1) == 'H') {
20+
return -1;
21+
} else {
22+
if (buckets[i - 1] == 1) {
23+
continue;
24+
} else {
25+
buckets[i - 1] = 1;
26+
minBuckets++;
27+
}
28+
}
29+
} else if (i + 1 >= street.length() && i - 1 < 0) {
30+
return -1;
31+
} else if (i - 1 >= 0 && street.charAt(i - 1) == '.') {
32+
if (buckets[i - 1] == 1) {
33+
continue;
34+
} else {
35+
minBuckets++;
36+
buckets[i - 1] = 1;
37+
}
38+
} else if (i + 1 >= street.length() && i - 1 >= 0 && street.charAt(i - 1) == 'H') {
39+
return -1;
40+
}
41+
}
42+
}
43+
return minBuckets;
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy