Reverse LinkedList I
字节,研发
Last updated
字节,研发
Last updated
{1,2,3}{3,2,1}# -*- coding:utf-8 -*-
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
# 返回ListNode
def ReverseList(self, pHead):
# write code here
if not pHead:
return pHead
prev = None
cur = pHead
while cur:
next_node = cur.next
cur.next = prev
prev = cur
cur = next_node
return prev