输入一个链表,反转链表后,输出链表的所有元素。

 1 # -*- coding:utf-8 -*-
 2 # class ListNode:
 3 #     def __init__(self, x):
 4 #         self.val = x
 5 #         self.next = None
 6 class Solution:
 7     # 返回ListNode
 8     def ReverseList(self, pHead):
 9         # write code here\
10         pCur = pHead
11         pPre = None
12         if pHead == None:
13             return pHead
14         while pCur != None:
15             pLat = pCur.next
16             pCur.next = pPre
17             pPre = pCur
18             pCur = pLat
19         return pPre

 

posted @ 2017-09-03 16:26  kuqs(奇小东)  阅读(167)  评论(0)    收藏  举报