LeetCode 1578. Minimum Time to Make Rope Colorful in F#
URL
Minimum Time to Make Rope Colorful - LeetCode
Code
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
Comments
Join the discussionNo comments yet. Be the first to comment.