---
# System prepended metadata

title: 2086. Minimum Number of Food Buckets to Feed the Hamsters
tags: [Leetcode, Medium, Greedy]

---

# 2086. Minimum Number of Food Buckets to Feed the Hamsters
###### tags: `Leetcode` `Medium` `Greedy`
Link: https://leetcode.com/problems/minimum-number-of-food-buckets-to-feed-the-hamsters/description/
## 思路
思路参考[这里](https://leetcode.com/problems/minimum-number-of-food-buckets-to-feed-the-hamsters/solutions/1598919/java-python-1-liner-solution/)
首先判断答案是-1的情况
由于每个hamster都需要一个bucket 先算出有几个hamster
由于'H.H'的情况 两个hamster可以share一个bucket 所以我们只需要greedy的算出一共有几个'H.H'即可 这个可以通过python的```string.count()```实现
## Code
```python=
class Solution:
    def minimumBuckets(self, hamsters: str) -> int:
        if 'HHH' in hamsters or hamsters[:2]=='HH' or hamsters[-2:]=='HH' or hamsters=='H':
            return -1
        else:
            return hamsters.count('H')-hamsters.count('H.H')
```