We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bffcf3a commit 5c94c03Copy full SHA for 5c94c03
solution/024.Swap Nodes in Pairs/Solution.py
@@ -0,0 +1,28 @@
1
+# Definition for singly-linked list.
2
+# class ListNode:
3
+# def __init__(self, x):
4
+# self.val = x
5
+# self.next = None
6
+
7
+class Solution:
8
+ def swapPairs(self, head):
9
+ """
10
+ :type head: ListNode
11
+ :rtype: ListNode
12
13
+ if (not head) or (not head.next):
14
+ return head
15
+ pre=head.next
16
+ p=head
17
+ q=head.next
18
19
+ while q:
20
+ t=q.next
21
+ q.next=p
22
+ if (not t) or (not t.next):
23
+ p.next=t
24
+ break
25
+ p.next=t.next
26
+ p=t
27
+ q=p.next
28
+ return pre
0 commit comments