<p>You are given a <strong>0-indexed</strong> string <code>hamsters</code> where <code>hamsters[i]</code> is either:</p>

<ul>
	<li><code>&#39;H&#39;</code> indicating that there is a hamster at index <code>i</code>, or</li>
	<li><code>&#39;.&#39;</code> indicating that index <code>i</code> is empty.</li>
</ul>

<p>You will add some number of food buckets at the empty indices in order to feed the hamsters. A hamster can be fed if there is at least one food bucket to its left or to its right. More formally, a hamster at index <code>i</code> can be fed if you place a food bucket at index <code>i - 1</code> <strong>and/or</strong> at index <code>i + 1</code>.</p>

<p>Return <em>the minimum number of food buckets you should <strong>place at empty indices</strong> to feed all the hamsters or </em><code>-1</code><em> if it is impossible to feed all of them</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/11/01/example1.png" style="width: 482px; height: 162px;" />
<pre>
<strong>Input:</strong> hamsters = &quot;H..H&quot;
<strong>Output:</strong> 2
<strong>Explanation:</strong> We place two food buckets at indices 1 and 2.
It can be shown that if we place only one food bucket, one of the hamsters will not be fed.
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/11/01/example2.png" style="width: 602px; height: 162px;" />
<pre>
<strong>Input:</strong> hamsters = &quot;.H.H.&quot;
<strong>Output:</strong> 1
<strong>Explanation:</strong> We place one food bucket at index 2.
</pre>

<p><strong class="example">Example 3:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/11/01/example3.png" style="width: 602px; height: 162px;" />
<pre>
<strong>Input:</strong> hamsters = &quot;.HHH.&quot;
<strong>Output:</strong> -1
<strong>Explanation:</strong> If we place a food bucket at every empty index as shown, the hamster at index 2 will not be able to eat.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= hamsters.length &lt;= 10<sup>5</sup></code></li>
	<li><code>hamsters[i]</code> is either<code>&#39;H&#39;</code> or <code>&#39;.&#39;</code>.</li>
</ul>

'''
這題是問說
給一串list
上面每格可能有哈姆太郎或者是空格
如果是空格，可以擺一盤食物在上面
一盤食物可以餵到左右兩邊的哈姆太郎
問說怎樣擺，才可以擺最少盤的食物，然後餵到全部的哈姆太郎

一開始想到的是
一盤食物，最好的情況是可以餵到兩邊的哈姆太郎
所以如果從頭開始loop
遇到哈姆太郎的話
就先看他前面，是不是已經有食物了
沒有的話，再看他後面有沒有空間可以擺食物
因為最好的情況是
已經有先餵了一隻在更之前的老鼠
    0 1 2
像是H . H
的情況
走到2的時候，可以先看之前有沒有東西可以吃
而1的食物，是為了要餵0而擺的

雖然後來筆記看起來好像很簡單
但是還是撞牆撞超久才撞出來
'''
class Solution:
    def minimumBuckets(self, hamsters: str) -> int:
        i = 0
        result = 0
        hamsters = [hamsters[i] for i in range(len(hamsters))]
        #而且題目給的hamsters本來是字串，還要多這步(不然字串沒辦法直接用位置改裡面的字)
        #這樣多花了一個N
        while i < len(hamsters):
            if hamsters[i] == 'H':
                if i-1 >= 0:
                    if hamsters[i-1] != 'F':
                        if i+1 < len(hamsters) and hamsters[i+1]=='.':
                            hamsters[i+1] = 'F'
                            result += 1
                        elif i-1 >= 0 and hamsters[i-1]=='.':
                            result += 1
                        else:
                            return -1
                else:
                    if i+1 < len(hamsters) and hamsters[i+1]=='.':
                            hamsters[i+1] = 'F'
                            result += 1
                    else:
                        return -1
            i += 1
        return result

              
                    





18400