Minimum Time to Make Rope Colorful LeetCode solution in Python
1# Runtime: 862 ms (Top 94.6%) | Memory: 27.26 MB (Top 71.4%)234class Solution:5def minCost(self, s: str, cost: List[int]) -> int:6ans = prev = 0 # index of previously retained letter7for i in range(1, len(s)):8if s[prev] != s[i]:9prev = i10else:11ans += min(cost[prev], cost[i])12if cost[prev] < cost[i]:13prev = i14return ans