Leetcode June Challenge - Day 2

Problem: LeetCode June Challenge - Day 2

Ideas:

  1. Since you are at the tail, you can copy the next node in the current one, and delete the next one.

Solution:

class Solution {
public:
    void deleteNode(ListNode* node) {
        node->val = node->next->val;
        ListNode *aux = node->next->next;
        delete node->next;
        node->next = aux;
    }
};