LeetCode 486. Predict the Winner in F#
URL
Code
https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/problems/0486/main.fsx
open System
let predictTheWinner (nums: int list) : bool =
let rec predictTheWinner' (nums: int[]) left right =
if left >= right then
nums.[left]
else
let leftMax = nums.[left] - (predictTheWinner' nums (left + 1) right)
let rightMax = nums.[right] - (predictTheWinner' nums left (right - 1))
Math.Max(leftMax, rightMax)
let nums' = Array.ofList nums
let maxScore = predictTheWinner' nums' 0 (nums'.Length - 1)
maxScore >= 0