2107. Number of Unique Flavors After Sharing K Candies

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

Содержание

LeetCode problem 2107

class Solution:
    def shareCandies(self, candies: List[int], k: int) -> int:
        cnt = Counter(candies[k:])
        res = len(cnt)
        for i in range(k, len(candies)):
            cnt[candies[i - k]] += 1
            cnt[candies[i]] -= 1
            if cnt[candies[i]] == 0:
                cnt.pop(candies[i])
            res = max(res, len(cnt))
        return res