Python反转链表

# -*- coding:utf-8 -*-
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None
class Solution:
    
    def ReverseList(self, pHead):
        if pHead is None:
            return
        last=None
        while pHead is not None:
            tmp=pHead.next
            pHead.next=last
            last=pHead
            pHead=tmp
            
        return last

 

posted on 2020-08-31 14:31  HHMLXL  阅读(153)  评论(0)    收藏  举报

导航