cft
Become a CreatorSign inGet Started

LeetCode 24. Swap Nodes in Pairs in F#

LeetCode Daily Problem at 2022/02/16


user

Shohei Yoshida

3 months ago | 1 min read
Follow

leetcode-24-swap-nodes-pairs-f-mogv9

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

Follow

A programmer of DeNA

A Programmer


people
Post

Upvote

Downvote

Comment

Bookmark

Share


Related Articles