code #!/usr/bin/python # -*- coding: utf- -*- class ListNode: def __init__(self,x): self.val=x self.next=None def recurse(head,newhead): #递归,head为原链表的头结点,newhead为反转后链表的头结点 if head is None: return if head.next is None: newhead=head else : newhead=recu…