Shohei Yoshida
Shohei Yoshida's Blog

Shohei Yoshida's Blog

LeetCode 300. Longest Increasing Subsequence in F#

Shohei Yoshida's photo
Shohei Yoshida
·Aug 8, 2022·

1 min read

URL

leetcode.com/problems/longest-increasing-su..

Code

github.com/syohex/dotnet-study/blob/master/..

let lengthOfLis (nums: int list) : int =
    let numsA = nums |> Array.ofList
    let dp = Array.init numsA.Length (fun _ -> 1)
    let mutable ret = 1

    for i in 1 .. (numsA.Length - 1) do
        for j in 0 .. (i - 1) do
            if numsA.[j] < numsA.[i] then
                dp.[i] <- System.Math.Max(dp.[i], dp.[j] + 1)

        ret <- System.Math.Max(ret, dp.[i])

    ret
 
Share this