Delete a node in the LinkedList


  • 0
    P
    void deleteNode(ListNode* node) {
            if(node->next != NULL)
            {
                ListNode * prev = node;
                ListNode * tmp = prev;
                tmp->val = tmp->next->val;
                tmp = node->next;
                while(tmp->next != NULL)
                {
                    prev = tmp;
                    tmp->val = tmp->next->val;
                    tmp = tmp->next;
                }
                prev->next = NULL;
            }
        }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.