Problem

Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.

Example
Given 1->2->3->4, and node 3. return 1->2->4

思路

  • 实际上删除target的下一个节点
    • 首先将target node的值换成它的下一个node值,
    public void deleteNode(ListNode node) {
        node.val = node.next.val;
        node.next = node.next.next;
    }

results matching ""

    No results matching ""