太简单了。
class Solution(object):
def reverseList(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
p=None
while head: head.next, p, head = p, head, head.next
return p
太简单了。
class Solution(object):
def reverseList(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
p=None
while head: head.next, p, head = p, head, head.next
return p