# 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:return None
if head.next==None:return head
nextHead=self.swapPairs(head.next.next)
h=head.next
h.next=head
h.next.next=nextHead
return h
LeetCode-24-Swap-Nodes-in-Pairs 链表递归水题
最新推荐文章于 2022-01-01 01:55:25 发布