Skip to main content

LeetCode 1578. Minimum Time to Make Rope Colorful in F#

Published 1 min readMarkdown

URL

Minimum Time to Make Rope Colorful - LeetCode

Code

dotnet-study/fsharp/leetcode/challenge/202511/minimum_time_to_make_rope_colorful/main.fsx at master · syohex/dotnet-study

let minCost (colors: string) (neededTime: int list) : int =
    let rec minCost' ct prev maxVal sum acc =
        match ct with
        | [] -> acc + (sum - maxVal)
        | (time, color) :: t ->
            if color = prev then
                minCost' t prev (max time maxVal) (sum + time) acc
            else
                minCost' t color time time (acc + sum - maxVal)


    let ct = colors |> Seq.toList |> List.zip neededTime
    minCost' ct '?' 0 0 0

No comments yet. Be the first to comment.

More from this blog