最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

leetcode 2086. Minimum Number of Food Buckets to Feed the Hamste

2022-12-30 12:24 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a?0-indexed?string?hamsters?where?hamsters[i]?is either:

  • 'H'?indicating that there is a hamster at index?i, or

  • '.'?indicating that index?i?is empty.

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?i?can be fed if you place a food bucket at index?i - 1?and/or?at index?i + 1.

Return?the minimum number of food buckets you should?place at empty indices?to feed all the hamsters or?-1?if it is impossible to feed all of them.

?

Example 1:


Input: hamsters = "H..H"Output: 2Explanation: 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.

Example 2:


Input: hamsters = ".H.H."Output: 1Explanation: We place one food bucket at index 2.

Example 3:


Input: hamsters = ".HHH."Output: -1Explanation: If we place a food bucket at every empty index as shown, the hamster at index 2 will not be able to eat.

?

Constraints:

  • 1 <= hamsters.length <= 105

  • hamsters[i]?is either'H'?or?'.'.

1:考慮邊界條件;

2:先將H中間有.的清出來,然后,再去遍歷剩下的H即可。

就是有點花時間了;


Runtime27 ms

Beats

10.8%

Memory50.4 MB

Beats

34.88%

這速度也是沒誰了,慢的快不及格了。。。


leetcode 2086. Minimum Number of Food Buckets to Feed the Hamste的評論 (共 條)

分享到微博請遵守國家法律
昭苏县| 渝中区| 达拉特旗| 庆阳市| 嘉鱼县| 宁蒗| 东宁县| 灵武市| 桑植县| 昌邑市| 唐海县| 钦州市| 伊川县| 樟树市| 梅州市| 青冈县| 辉县市| 克拉玛依市| 保德县| 保定市| 方正县| 桐乡市| 隆尧县| 年辖:市辖区| 句容市| 额敏县| 宾川县| 东明县| 陇南市| 二连浩特市| 满洲里市| 安溪县| 察隅县| 龙南县| 合作市| 富蕴县| 泗阳县| 蒙山县| 平潭县| 蓬安县| 黄大仙区|