給定1個單鏈表中的1個等待被刪除的節點(非表頭或表尾)。請在在O(1)時間復雜度刪除該鏈表節點。
這個刪除結點的方式很好
把需要刪除結點的值用后面1個結點值更新
刪除后面的那個結點
public class Solution {
/**
* @param node: the node in the list should be deleted
* @return: nothing
*/
public void deleteNode(ListNode node) {
// write your code here
if(node==null)
return;
node.val = node.next.val;
node.next = node.next.next;
}
}