LeetCode 896. Monotonic Array in F#
URL
Code
https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/problems/0896/main.fsx
let isMonotonic (nums: int list) : bool =
match nums with
| [] -> failwith "never reach here"
| _ :: [] -> true
| _ ->
let cmps =
nums
|> List.windowed 2
|> List.map (fun a -> compare (List.head a) (List.tail a |> List.head))
List.forall (fun c -> c >= 0) cmps || List.forall (fun c -> c <= 0) cmps