From 3c5ed1ebae1a0766f27797182d69c33238251995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=AA=E9=A3=9E?= Date: Tue, 18 May 2021 12:30:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E2=80=9C24.=E4=B8=A4?= =?UTF-8?q?=E4=B8=A4=E4=BA=A4=E6=8D=A2=E9=93=BE=E8=A1=A8=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E2=80=9DJavascript=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0024.两两交换链表中的节点.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/problems/0024.两两交换链表中的节点.md b/problems/0024.两两交换链表中的节点.md index 132d65bb..bda64da6 100644 --- a/problems/0024.两两交换链表中的节点.md +++ b/problems/0024.两两交换链表中的节点.md @@ -132,6 +132,21 @@ Python: Go: +Javascript: +```javascript +var swapPairs = function (head) { + let ret = new ListNode(0, head), temp = ret; + while (temp.next && temp.next.next) { + let cur = temp.next.next, pre = temp.next; + pre.next = cur.next; + cur.next = pre; + temp.next = cur; + temp = pre; + } + return ret.next; +}; +``` + ----------------------- * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)