Leetcode 237. Delete Node in a Linked List

Description: Write a function to delete a node in a singly-linked list. You will not be given access to the head of the list, instead you will be given access to the node to be deleted directly.

It is guaranteed that the node to be deleted is not a tail node in the list.

Link: https://leetcode.com/problems/delete-node-in-a-linked-list/

Code:

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

日期: 2020-12-01

posted @ 2020-12-01 16:09  summer_mimi  阅读(65)  评论(0编辑  收藏  举报