题目
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