LeetCode 237 Delete Node in a Linked List (Python)

Posted by 小明MaxMing on June 2, 2020

题目

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.

解题思路

使给的节点的值等于下一个节点的值,并删除下一个节点

代码

class Solution:
    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

视频讲解 YouTube<--欢迎点击订阅

视频讲解 bilibili<--欢迎点击订阅