写一个函数实现删除链表中的节点,给定的输入数据只有待删除的节点
给定链表--head = [4,5,1,9],形式为
4 -> 5 -> 1 -> 9
Example 1:
Input: head = [4,5,1,9], node = 5 Output: [4,1,9] Explanation: You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function.Example 2:
Input: head = [4,5,1,9], node = 1 Output: [4,5,9] Explanation: You are given the third node with value 1, the linked list should become 4 -> 5 -> 9 after calling your function.
注意:
链表至少有两个节点
所有节点的值均唯一,不重复
给定的节点不是尾节点,并且在链表中总是有效
函数不需要返回任何东西
1:node.val = node.next.val、node.next = node.next.next
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
算法题来自:https://leetcode-cn.com/problems/delete-node-in-a-linked-list/description/