# 样例 1

``````输入：

``````

# 分析

• 链表前一个节点存有下一个节点的地址，一般的删除节点，是直接将当前节点的上一个节点与当前节点的下一个节点相连。
• 本题只传入要删除的节点，所以当前节点的地址是不能变的，也就只能改变值了。在业务的角度看，并不关心链表的地址，关心的是里面的值，所以我们只要让值看起来是删掉了，就算是删除了当前节点。
• 这道题官方不让选rust，二当家的只好舍掉。

# 题解

## java

``````/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */
class Solution {

public void deleteNode(ListNode node) {

node.val = node.next.val;
node.next = node.next.next;
}
}
``````

## c

``````/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */
void deleteNode(struct ListNode* node) {

node->val = node->next->val;
node->next = node->next->next;
}
``````

## c++

``````/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */
class Solution {

public:
void deleteNode(ListNode* node) {

node->val = node->next->val;
node->next = node->next->next;
}
};
``````

## python

``````# 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. """
node.val = node.next.val
node.next = node.next.next
``````

## go

``````/** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */
func deleteNode(node *ListNode) {

node.Val = node.Next.Val
node.Next = node.Next.Next
}
``````

# 原题传送门：https://leetcode-cn.com/problems/delete-middle-node-lcci/

https://le-yi.blog.csdn.net/article/details/120823784