小白刷题笔记
官网给出了两个方法:递归法和迭代法
递归法代码
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
用两个指针完成反转,prev和crr指针不断往后移