From 4e2f941873ec12aace9a3f8d824067829996ba49 Mon Sep 17 00:00:00 2001 From: defuncc Date: Mon, 22 Apr 2019 21:42:08 +0800 Subject: [PATCH] Create 24.py --- Week_01/id_19/24.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Week_01/id_19/24.py diff --git a/Week_01/id_19/24.py b/Week_01/id_19/24.py new file mode 100644 index 00000000..ccac0597 --- /dev/null +++ b/Week_01/id_19/24.py @@ -0,0 +1,11 @@ + +class Solution: + def swapPairs(self, head): + dummy = pre = ListNode(0) + pre.next = head + while pre.next and pre.next.next: + a = pre.next + b = a.next + pre.next, a.next, b.next = b, b.next, a + pre = a + return dummy.next