LeetCode 205. Isomorphic Strings in F#

URL

https://leetcode.com/problems/isomorphic-strings/description/

Code

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

let isIsomorphic (s: string) (t: string) : bool =
    let rec isIsomorphic' cs m mapped =
        match cs with
        | [] -> true
        | (c1, c2) :: t ->
            match Map.tryFind c1 m with
            | Some(v) -> if v = c2 then isIsomorphic' t m mapped else false
            | None ->
                if Set.contains c2 mapped then
                    false
                else
                    isIsomorphic' t (Map.add c1 c2 m) (Set.add c2 mapped)

    let cs = s |> Seq.zip t |> Seq.toList
    isIsomorphic' cs Map.empty Set.empty