LeetCode 24. Swap Nodes in Pairs in F#

URL

Swap Nodes in Pairs - LeetCode

Code

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

type ListNode =
    | Leaf
    | Node of int * ListNode

let swapPair (head: ListNode) =
    let rec swapPair' node =
        match node with
        | Leaf -> Leaf
        | Node(v1, next1) ->
            match next1 with
            | Leaf -> node
            | Node(v2, next2) -> Node(v2, Node(v1, swapPair' next2))

    swapPair' head