class ListNode:
def __init__(self, x):
self.val = x
self.next = None

class Solution:
def swapPairs(self, head: ListNode) -> ListNode:
# 界定一个连接点 ,并将它偏向头节点
node = ListNode(0)
cur = node
cur.next = head
# 那样写是由于合数连接点最后一个连接点无需翻转
while cur.next and cur.next.next:
# 界定连接点意味着必须翻转的连接点 。
node1,node2 = cur.next,cur.next.next
# 开展翻转
cur.next,node2.next,node1.next = node2,node1,node2.next
# 升级当今连接点到下2个必须翻转的连接点前 。
cur = node1
return node.next

文章来源于网络 ,如有侵权请联系站长QQ61910465删除
本文版权归qu快排seo www.sEoguRuBlog.com 所有,如有转发请注明来出,竞价开户托管,seo优化请联系QQ√61910465