Problem
Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.
Note
就是把node.next.val
赋给node
,然后删掉node.next
,用node
直接连接node.next.next
。
Solution
public class Solution {
public void deleteNode(ListNode node) {
if (node == null) return;
if (node.next != null) {
node.val = node.next.val;
node.next = node.next.next;
}
return;
}
}