LeetCode 300. Longest Increasing Subsequence in F#

URL

https://leetcode.com/problems/longest-increasing-subsequence/description/

Code

https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/challenge/202401/longest_increasing_subsequence/main.fsx

let lengthOfLIS (nums: int list) : int =
    let nums' = Array.ofList nums
    let len = Array.length nums'
    let dp = Array.init len (fun _ -> 1)

    for i in 1 .. (len - 1) do
        for j in 0 .. (i - 1) do
            if nums'.[i] > nums'.[j] && dp.[j] + 1 > dp.[i] then
                dp.[i] <- dp.[j] + 1

    Array.max dp