2086. Minimum Number of Food Buckets to Feed the Hamsters

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 2086

class Solution:
    def minimumBuckets(self, street: str) -> int:
        res = 0
        i, n = 0, len(street)
        while i < n:
            if street[i] == 'H':
                if i + 1 < n and street[i + 1] == '.':
                    i += 2
                    res += 1
                elif i and street[i - 1] == '.':
                    res += 1
                else:
                    return -1
            i += 1
        return res