LeetCode 24. Swap Nodes in Pairs in F#
LeetCode Daily Problem at 2022/02/16
Shohei Yoshida
2 years ago | 1 min read
URL
Swap Nodes in Pairs - LeetCode
Code
https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/problems/0024/main.fsx
type LinkedList =
| Empty
| ListNode of int * LinkedList
let rec swapPair (node: LinkedList) : LinkedList =
match node with
| Empty -> Empty
| ListNode (x, next) ->
match next with
| Empty -> node
| ListNode (y, nnext) -> ListNode(y, ListNode(x, (swapPair nnext)))
I think this problem is not suit for F#
Upvote
Created by
Shohei Yoshida
A Programmer
Post
Related Articles