Implement an algorithm to delete a node in the middle of the singly linked list (that is, not the first or last node), assuming that you can only access the node.
Example:
Input: node c in the singly linked list a->b->c->d->e->f
Result: no data is returned, but the linked list becomes a->b->d->e->f
Source: LeetCode (LeetCode)
Link: https://leetcode-cn.com/problems/delete-middle-node-lcci The
copyright is owned by LeetCode . For commercial reprints, please contact the official authorization. For non-commercial reprints, please indicate the source.
public class DeleteNode {
//:A->B->C->D ->E
// 将C节点 变成 D 节点
public void deleteNode(ListNode node) {
node.val=node.next.val;
node.next=node.next.next;
}
}
class ListNode{
int val;
ListNode next;
ListNode(int x){
val=x;
}
}