递归,head。next。next让head和head。next形成回环,再用head。next=null消除回环
class Solution:
def reverseList(self
, head
: ListNode
) -> ListNode
:
if head
== None or head
.next == None:
return head
p
= self
.reverseList
(head
.next)
head
.next.next = head
head
.next = None
return p
转载请注明原文地址: https://mac.8miu.com/read-78237.html