# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    def swapPairs(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        if head == None or head.next == None:
            return head
        dummy=ListNode(0)
        dummy.next=head
        p=dummy
        while p.next and p.next.next:
            tmp=p.next.next
            p.next.next=tmp.next
            tmp.next=p.next
            p.next=tmp
            p=p.next.next
        return dummy.next

 

相关文章:

  • 2021-08-20
  • 2021-09-24
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
猜你喜欢
  • 2021-08-13
  • 2021-05-21
  • 2022-03-01
  • 2021-09-10
相关资源
相似解决方案