LeetCode 1266. Minimum Time Visiting All Points in F#
URL
Code
https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/problems/1266/main.fsx
open System
let minTimeToVisitAllPoints (points: (int * int) list) =
let rec minTimeToVisitAllPoints' (points: (int * int) list) (prevX, prevY) acc =
match points with
| [] -> acc
| (x, y) :: t ->
let dist = Math.Max(Math.Abs(x - prevX), Math.Abs(y - prevY))
minTimeToVisitAllPoints' t (x, y) (acc + dist)
match points with
| [] -> failwith "never reach here"
| _ :: [] -> 0
| (x, y) :: t -> minTimeToVisitAllPoints' t (x, y) 0