思考一下就行
趣味题。
因为我们无法拿到node之前的节点previous,因此无法通过previous.next = node.next来删除节点。我们只需要把后面一位的值复制到此位,然后删除后面那位即可。
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public void deleteNode(ListNode node) {
node.val = node.next.val;
node.next = node.next.next;
}
}
原文:https://www.cnblogs.com/fromneptune/p/13266910.html