Swap-nodes-in-pairs

作者: shaneZhang 分类: 算法与数据结构 发布时间: 2020-05-18 16:43
def swapInPairs(self, head):
    pre, pre.next = self, head
    while pre.next and pre.next.next:
        a = pre.next
        b = a.next
        pre.next, b.next, a.next = b, a, b.next
        pre = a
    return self.next 

detail setp is below the picture:

本页面支持繁体中文友好显示:Swap-nodes-in-pairs

如果觉得我的文章对您有用,请随意打赏。如果有其他问题请联系博主QQ(909491009)或者下方留言!

发表回复