将一个链如下反转:

输入链 : 1 -> 2 -> 3 -> 4

输出    : 2 -> 1 -> 4 -> 3

 

python

def swap(head):
    if (head == None) or (head.next== None):
        return head

        tmp = ListNode()
        tmp = head.next
        head.next = swap(tmp.next)
        tmp.next = head

 

相关文章:

  • 2022-01-28
  • 2022-12-23
  • 2021-08-07
  • 2022-12-23
  • 2022-01-21
  • 2021-05-15
  • 2021-06-16
猜你喜欢
  • 2022-12-23
  • 2022-03-09
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2022-01-12
  • 2021-08-20
相关资源
相似解决方案