classSolution(object):defswapPairs(self, head):"""
:type head: ListNode
:rtype: ListNode
"""
psnode = ListNode(next= head)
pre = psnode
while pre.nextisnotNoneand pre.next.nextisnotNone:
cur = pre.next
post = pre.next.next
temp = post.next
pre.next= post
post.next= cur
cur.next= temp
pre = cur
return psnode.next
classSolution(object):defdetectCycle(self, head):"""
:type head: ListNode
:rtype: ListNode
"""
fast = head
slow = head
while fast isnotNoneand fast.nextisnotNone:
fast = fast.next.next
slow = slow.nextif fast == slow:
index1 = head
index2 = fast
while index1 != index2:
index1 = index1.next
index2 = index2.nextreturn index1
returnNone