LeetCode 392. Is Subsequence in F#

URL

Is Subsequence - LeetCode

Code

https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/challenge/202309/is_subsequence/main.fsx

let isSubsequence (s: string) (t: string) : bool =
    let rec isSubsequence' cs ts =
        match cs with
        | [] -> true
        | h :: rest ->
            match List.tryFindIndex ((=) h) ts with
            | None -> false
            | Some(idx) -> isSubsequence' rest (List.skip (idx + 1) ts)

    isSubsequence' (List.ofSeq s) (List.ofSeq t)