1
class Solution:
2
def swapPairs(self, head: Optional[ListNode]) -> Optional[ListNode]:
3

4
if not head or not head.next:
5
return head
6

7
dummy = ListNode(0)
8
dummy.next = head
9
curr = dummy
10

11
while curr.next and curr.next.next:
12
first = curr.next
13
second = curr.next.next
14
curr.next = second
15
first.next = second.next
16
second.next = first
17
curr = curr.next.next
18

19
return dummy.next

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0