Skip to content

Commit 98f8e52

Browse files
committed
Single new question for testing
1 parent 85dd842 commit 98f8e52

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ Profile: [Zanger](https://leetcode.com/u/Zanger/)
280280
| 2013 | [Detect Squares](<https://leetcode.com/problems/detect-squares>) | Medium | N150 | [solution](<markdowns/_2013. Detect Squares.md>) | py |
281281
| 2037 | [Minimum Number of Moves to Seat Everyone](<https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone>) | Easy | Daily | [solution](<markdowns/_2037. Minimum Number of Moves to Seat Everyone.md>) | py, c |
282282
| 2083 | [Substrings That Begin and End With the Same Letter](<https://leetcode.com/problems/substrings-that-begin-and-end-with-the-same-letter>) | Medium | Weekly Premium | [solution](<markdowns/_2083. Substrings That Begin and End With the Same Letter.md>) | py, c |
283+
| 2086 | [Minimum Number of Food Buckets to Feed the Hamsters](<https://leetcode.com/problems/minimum-number-of-food-buckets-to-feed-the-hamsters>) | Medium | | [solution](<markdowns/_2086. Minimum Number of Food Buckets to Feed the Hamsters.md>) | java |
283284
| 2095 | [Delete the Middle Node of a Linked List](<https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list>) | Medium | | [solution](<markdowns/_2095. Delete the Middle Node of a Linked List.md>) | java, c |
284285
| 2130 | [Maximum Twin Sum of a Linked List](<https://leetcode.com/problems/maximum-twin-sum-of-a-linked-list>) | Medium | | [solution](<markdowns/_2130. Maximum Twin Sum of a Linked List.md>) | py |
285286
| 2149 | [Rearrange Array Elements by Sign](<https://leetcode.com/problems/rearrange-array-elements-by-sign>) | Medium | | [solution](<markdowns/_2149. Rearrange Array Elements by Sign.md>) | py, c |
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# 2086. [Minimum Number of Food Buckets to Feed the Hamsters](<https://leetcode.com/problems/minimum-number-of-food-buckets-to-feed-the-hamsters>)
2+
3+
*First added: July 01, 2024*
4+
5+
*First added: July 01, 2024*
6+
7+
8+
> *To see the question prompt, click the title.*
9+
10+
**Topics:** String, Dynamic Programming, Greedy
11+
12+
**AC %:** 46.157
13+
14+
15+
## Solutions
16+
17+
- [m2086.java](<../my-submissions/m2086.java>)
18+
### Java
19+
#### [m2086.java](<../my-submissions/m2086.java>)
20+
```Java
21+
class Solution {
22+
public int minimumBuckets(String hamsters) {
23+
int counter = 0;
24+
25+
for (int i = 0; i < hamsters.length(); i++) {
26+
if (hamsters.charAt(i) != 'H') {
27+
continue;
28+
}
29+
counter++;
30+
31+
if ((i == hamsters.length() - 1 || hamsters.charAt(i + 1) == 'H') && (i == 0 || hamsters.charAt(i - 1) == 'H')) {
32+
return -1;
33+
}
34+
if (i != hamsters.length() - 1 && hamsters.charAt(i + 1) != 'H') {
35+
i += 2;
36+
}
37+
}
38+
39+
return counter;
40+
}
41+
}
42+
```
43+

my-submissions/m2086.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public int minimumBuckets(String hamsters) {
3+
int counter = 0;
4+
5+
for (int i = 0; i < hamsters.length(); i++) {
6+
if (hamsters.charAt(i) != 'H') {
7+
continue;
8+
}
9+
counter++;
10+
11+
if ((i == hamsters.length() - 1 || hamsters.charAt(i + 1) == 'H') && (i == 0 || hamsters.charAt(i - 1) == 'H')) {
12+
return -1;
13+
}
14+
if (i != hamsters.length() - 1 && hamsters.charAt(i + 1) != 'H') {
15+
i += 2;
16+
}
17+
}
18+
19+
return counter;
20+
}
21+
}

0 commit comments

Comments
 (0)