一、leetcode地址
https://leetcode.com/problems/reverse-linked-list/
二、问题描述
三、代码实现
语言:Python3
代码:
class Solution:
def reverseList(self, head: ListNode) -> ListNode:
if head == None:
return head
temp = head.next
head.next = None
temp_next = head
while temp:
temp1 = temp.next if temp.next else None
temp.next = temp_next
temp_next = temp
temp = temp1
return temp_next