1578. Minimum Time to Make Rope Colorful

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

Содержание

LeetCode problem 1578

class Solution:
    def minCost(self, colors: str, neededTime: List[int]) -> int:
        res = i = 0
        n = len(colors)
        while i < n:
            j = i
            s = mx = 0
            while j < n and colors[j] == colors[i]:
                s += neededTime[j]
                if mx < neededTime[j]:
                    mx = neededTime[j]
                j += 1
            if j - i > 1:
                res += s - mx
            i = j
        return res