class ListNode(object): def __init__(self, x): self.val = x self.next = None def reverseList(self, head): if head == None or head.next == None: return head p = head.next while p.next: p1 = p.next p.next = head head, p = p, p1 p.next = head return p
class ListNode(object): def __init__(self, x): self.val = x self.next = None def reverseList(self, head): if head == None or head.next == None: return head p = head.next while p.next: p1 = p.next p.next = head head, p = p, p1 p.next = head return p
转载于:https://www.cnblogs.com/weswes/p/10084178.html