You are viewing a single comment's thread. Return to all comments →
Just to clear up any confusion, the above solution has memory leaks. This solution does not deallocate the memory of the node at the target index.
This is the C++ solution with memory cleanup:
Node* Delete(Node *head, int position) { if (position == 0) { auto next = head->next; delete head; return next; } head->next = Delete(head->next, position - 1); return head; }
Seems like cookies are disabled on this browser, please enable them to open this website
Delete a Node
You are viewing a single comment's thread. Return to all comments →
Just to clear up any confusion, the above solution has memory leaks. This solution does not deallocate the memory of the node at the target index.
This is the C++ solution with memory cleanup: