LeetCode 350. Intersection of Two Arrays II in F#

URL

https://leetcode.com/problems/intersection-of-two-arrays-ii/description/

Code

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

let intersect (nums1: int list) (nums2: int list) : int list =
    let rec intersect' nums1 nums2 acc =
        match nums1, nums2 with
        | [], []
        | _, []
        | [], _ -> List.rev acc
        | h1 :: t1, h2 :: t2 ->
            if h1 < h2 then intersect' t1 nums2 acc
            elif h1 > h2 then intersect' nums1 t2 acc
            else intersect' t1 t2 (h1 :: acc)

    intersect' (List.sort nums1) (List.sort nums2) []