给定一个单链表中的一个等待被删除的节点(非表头或表尾)。请在在O(1)时间复杂度删除该链表节点。
样例
样例
Linked list is 1->2->3->4, and given node 3, delete the node in place 1->2->4
/**
* Definition for ListNode.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int val) {
* this.val = val;
* this.next = null;
* }
* }
*/
public class Solution {
/**
* @param node: the node in the list should be deleted
* @return: nothing
*/
public void deleteNode(ListNode node) {
if(node==null)
return;
ListNode p=node.next;
int temp=p.val;
p.val=node.val;
node.val=temp;
node.next=p.next;
}
}