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;
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。