Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 10. 3. 23:45

https://leetcode.com/problems/minimum-time-to-make-rope-colorful/

 

Minimum Time to Make Rope Colorful - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

솔루션을 따라 했는데도 이해가 잘 안됨 =_=; 
몇 일 쉬어서 그런듯..?

class Solution:
    def minCost(self, colors: str, neededTime: List[int]) -> int:
        total_time = 0
        i, j = 0, 0
        
        while i < len(neededTime) and j < len(neededTime):
            curr_total = 0
            curr_max = 0
            
            while j < len(neededTime) and colors[i] == colors[j]:
                curr_total += neededTime[j]
                curr_max = max(curr_max, neededTime[j])
                j += 1
                
            total_time += curr_total - curr_max
            i = j
        
        return total_time
반응형