zoukankan      html  css  js  c++  java
  • 每日一题力扣206

    反转一个单链表。

    class Solution:
        def reverseList(self, head: ListNode) -> ListNode:
            if head is None or head.next is None:
                return head
            # pre 就是那个空链表
            pre, cur = None, head
            # 不断将当前链表移动到空链表上
            while cur:#cur是当前的点
                next_node = cur.next#保存当前节点的后面内容
                cur.next = pre#链接到等于新链表
                pre = cur#赋给新链表
                cur = next_node#再把cur往后移动
            return pre
  • 相关阅读:
    hdoj:2075
    hdoj:2072
    hdoj:2071
    hdoj:2070
    hdoj:2069
    test001
    hdoj:2067
    hdoj:2061
    hdoj:2058
    hdoj:2057
  • 原文地址:https://www.cnblogs.com/liuxiangyan/p/14532288.html
Copyright © 2011-2022 走看看