20250716|【继续19的快慢指针】Leetcodehot100之237【pass】&今天计划

20250716

  • Definition for singly-linked list.
    • 怎么设置比它快多少呢?
    • 如果给head是这么做。

20250716|【继续19的快慢指针】Leetcodehot100之237【pass】&今天计划_第1张图片
题目

20250716|【继续19的快慢指针】Leetcodehot100之237【pass】&今天计划_第2张图片

Definition for singly-linked list.

class ListNode(object):
def init(self, x):
self.val = x
self.next = None

实际就是把那题的n替换成现在的value

dummy -> 0 -> 1 -> 2 -> 3 -> null
del 2

fast = null
slow = del_pre

怎么设置比它快多少呢?

fast 在前找到del
slow 就是del_pre

如果给head是这么做。

但是现在只给node,一般删除是找前驱,所以想到交换cur与next

class Solution(object):
    def deleteNode(self, node):
        """
        :type node: ListNode
        :rtype: void Do not return anything, modify node in-place instead.
        """
        node.val = node.next.val
        node.next = node.next.next

你可能感兴趣的:(17boy,python)