1. 首页
  2. 数据库
  3. 其它
  4. LeetCode解题心得——反转链表(python)

LeetCode解题心得——反转链表(python)

上传者: 2020-12-22 23:53:27上传 PDF文件 28.43KB 热度 17次
题目 反转一个单链表。 示例: 输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->NULL 思路 1.递归 class Solution: def reverseList(self, head: ListNode) -> ListNode: if head == None or head.next == None: return head next = head.next new_head = self.reverseList(next) next.next =
用户评论