class Solution(object):
def swapPairs(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
ans=ListNode(0)
res=ans
ans.next=head
while head and head.next:
p=head.next
head.next=p.next
ans.next=p
p.next=head
ans=head
head=head.next
return res.next
python leetcode 24. Swap Nodes in Pairs
最新推荐文章于 2024-07-12 16:16:27 发布