@Scrazy
2017-04-13T06:26:42.000000Z
字数 290
阅读 878
python 算法
思路:
1. 创建一个新的头节点 pre
2. head 节点指向 pre
3. 循环
改变指针方向
1->2->3->4
1<-2<-3-<4
# -*- coding:utf-8 -*-# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution:# 返回ListNodedef ReverseList(self, pHead):pre = Nonenext = Nonewhile pHead:next = pHead.nextpHead.next = prepre = pHeadpHead = nextreturn pre
