请编写一个函数,使其可以删除某个链表中给定的(非末尾)节点,你将只被给定要求被删除的节点。
现有一个链表 -- head = [4,5,1,9],它可以表示为:

示例 1:
输入: head = [4,5,1,9], node = 5输出: [4,1,9]解释: 给定你链表中值为 5 的第二个节点,那么在调用了你的函数之后,该链表应变为 4 -> 1 -> 9.
示例 2:
输入: head = [4,5,1,9], node = 1输出: [4,5,9]解释: 给定你链表中值为 1 的第三个节点,那么在调用了你的函数之后,该链表应变为 4 -> 5 -> 9.
说明:
我的解题:
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def deleteNode(self, node):
"""
:type node: ListNode
:rtype: void Do not return anything, modify node in-place instead.
"""
# 将指定节点的下一个节点值赋值给本节点,并将下下节点指向下节点。
nextnode = node.next
after_nexnode = node.next.next
node.val = nextnode.val
node.next = after_nexnode
执行用时 : 64 ms, 在Delete Node in a Linked List的Python3提交中击败了55.73% 的用户
内存消耗 : 13.5 MB, 在Delete Node in a Linked List的Python3提交中击败了81.89% 的用户