标签:solution class odi 反转链表 self 思路 code 操作 python
题目描述
输入一个链表,反转链表后,输出新链表的表头。
解题思路
直接在原链表上操作,不需要新的链表
python solution:
# -*- coding:utf-8 -*-
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
class Solution:
# 返回ListNode
def ReverseList(self, pHead):
pre,next = None,None
while pHead is not None:
next = pHead.next
pHead.next = pre
pre = pHead
pHead = next
return pre
标签:solution class odi 反转链表 self 思路 code 操作 python
原文地址:https://www.cnblogs.com/bernieloveslife/p/10423295.html