剑指offer-反转链表15

题目描述

输入一个链表,反转链表后,输出新链表的表头。
class Solution:
    # 返回ListNode
    def ReverseList(self, pHead):
        # write code here
        nextNode=None
        p=pHead
        while pHead is not None:
            pHead=pHead.next
            p.next=nextNode
            nextNode=p
            p=pHead
        return nextNode

猜你喜欢

转载自www.cnblogs.com/zhaiyansheng/p/10414807.html