2.3 Delete Middle Node

来源:互联网 发布:将神 鬼神吕布数据 编辑:程序博客网 时间:2024/06/16 08:08

The question requires that: we are not given access to the head of linked list. We only have access to the node which is going to be deleted.

So the solution is simply copying next node to the node which is going to be deleted.

    void deleteNode(ListNode* node) {        ListNode* tmp = node->next;        *node = *node->next;        delete tmp;    }
0 0
原创粉丝点击