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
最新推荐文章于 2025-12-08 12:04:40 发布
本文介绍了一种链表操作的算法,通过Python实现链表中节点的成对交换,详细解析了算法流程及其实现代码。

202

被折叠的 条评论
为什么被折叠?



