classSolution:defReverseList(self , head: ListNode)-> ListNode:
pre, cur =None, head
while cur isnotNone:
k = cur.next
cur.next= pre
pre = cur
cur = k
return pre
classSolution(object):defswapPairs(self, head):
pre = self
pre.next= head # 这里pre是solution,next相当于他的一个属性while pre.nextand pre.next.next:# pre来回变化,从solution类型转换为ListNode类型
a = pre.next
b = pre.next.next
pre.next= b
a.next= b.next
b.next= a
pre = a
return self.next