Python链表成对调换

1->2->3->4 转换成 2->1->4->3
 
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None
class Solution:
    # @param a ListNode
    # @return a ListNode
    def swapPairs(self, head):
        if head != None and head.next != None:
            next = head.next
            head.next = self.swapPairs(next.next)
            next.next = head
        return next
        return head                       

 

posted @ 2020-04-23 09:29  燕十三丶  阅读(283)  评论(0编辑  收藏  举报
AmazingCounters.com