cft

LeetCode 24. Swap Nodes in Pairs in F#

LeetCode Daily Problem at 2022/02/16


user

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


user
Created by

Shohei Yoshida

A Programmer


people
Post

Upvote

Downvote

Comment

Bookmark

Share


Related Articles