Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node. EXAMPLE
Input: the node ‘c’ from the linked list a->b->c->d->e
Result: nothing is returned, but the new linked list looks like a->b->d->e

My initial thoughts:
We need to consider two cases: if that node is the head, then we need to update head pointer to the next one. If that node is in the middle, then we need to update the previous pointer.

My initial codes:

```
public static void deleteANode(LLNode head, LLNode item) {
item.setNext(null);
return;
}
while (current != null) {
if (current == item) {
previous.setNext(current.getNext());
current.setNext(null);
return;
} else {
previous = current;
current = current.getNext();
}
}
return;
}

It works fine with O(n) time complexity and O(1) space complexity.
After reading the solution, I found out that the question explicitly specifies that only the access to that node is given therefore you don’t know the head pointer.

Solution:
public static void deleteNode(LLNode node) {
if (node == null || node.getNext() == null)
return;
LLNode nextNode = node.getNext();
node.setData(nextNode.getData());
node.setNext(nextNode.getNext());
nextNode.setNext(null);
}

If that node happens to be at the end, then there’s no way to delete it without knowing the previous node.

__ATA.cmd.push(function() {
__ATA.initVideoSlot('atatags-370373-5bcfc5509ae12', {
sectionId: '370373',
});
});

__ATA.cmd.push(function() {
__ATA.initSlot('atatags-26942-5bcfc5509ae6e',  {
collapseEmpty: 'before',
sectionId: '26942',
width: 300,
height: 250
});
});

__ATA.cmd.push(function() {
__ATA.initSlot('atatags-114160-5bcfc5509ae71',  {
collapseEmpty: 'before',
sectionId: '114160',
width: 300,
height: 250
});
});

Related
```