Title Description
Please write a function that makes it possible to delete a list given (non-end) node, you will only be required for a given node is removed.
A list of existing - head = [4,5,1,9], it can be expressed as:
4-> 5-> 1-> 9
Example 1:
Input: head = [4,5,1,9], node = 5
Output: [4,1,9]
After a given second node in the list you value of 5, then call your function: Dictionary the list strain 4 -> 1 -> 9.
Example 2:
Input: head = [4,5,1,9], node = 1
Output: [4,5,9]
After a given value 1 of the list you third node, then call your function: Dictionary the list strain 4 -> 5 -> 9.
Description:
the list comprises at least two nodes.
The value of all the nodes in the list are unique.
Non given node and the end node must be a valid node in the linked list.
Do not return any results from your functions.
Thinking
subject of the request to delete the current node node, the difficulty lies in not knowing how the precursor node, the node point to make the precursor successor node of the current node.
Algorithm thought
the contents of a node after node copied to the node node, and then delete a node after the node.
Code
public class Solution {
public void deleteNode(ListNode node){
node.val = node.next.val;
ListNode nextTemp = node.next.next;
node.next = nextTemp;
}
}
Performance