From b02a1c44f25823e0a09985c277f7cb41a543b2b7 Mon Sep 17 00:00:00 2001 From: NevS <1173325467@qq.com> Date: Thu, 27 May 2021 00:13:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=200024.=E4=B8=A4=E4=B8=A4?= =?UTF-8?q?=E4=BA=A4=E6=8D=A2=E9=93=BE=E8=A1=A8=E4=B8=AD=E7=9A=84=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E7=9A=84=E9=80=92=E5=BD=92=E8=A7=A3=E6=B3=95=20go=20?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0024.两两交换链表中的节点.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/problems/0024.两两交换链表中的节点.md b/problems/0024.两两交换链表中的节点.md index 8d6a394d..643f6055 100644 --- a/problems/0024.两两交换链表中的节点.md +++ b/problems/0024.两两交换链表中的节点.md @@ -153,6 +153,19 @@ func swapPairs(head *ListNode) *ListNode { } ``` +```go +// 递归版本 +func swapPairs(head *ListNode) *ListNode { + if head == nil || head.Next == nil { + return head + } + next := head.Next + head.Next = swapPairs(next.Next) + next.Next = head + return next +} +``` + Javascript: ```javascript var swapPairs = function (head) {