Cpp solution, but its ACTUALLY SC: O(1)
After solving this question when I came to discuss section, I saw solutions where they are saying that its space complexity is O(1) and are either making a whol
After solving this question when I came to discuss section, I saw solutions where they are saying that its space complexity is O(1) and are either making a whole new linked list or not freeing up the memory, causing memory leak. In both of the cases, the interviewer will show you the path to the door.\n\n```\nclass Solution {\npublic:\n    \n    void del(ListNode* node)\n    {\n        if(node->next == NULL){\n            node = NULL;\n            return;\n        }\n        ListNode* toDel = node->next;\n        node->next = toDel->next;\n        delete toDel;\n    }\n    \n    \n    ListNode* mergeNodes(ListNode* head)\n    {\n        ListNode* dummy = new ListNode(-1);\n        dummy->next = head;\n        temp = dummy;\n        while(temp!=NULL)\n        {\n            if(temp->val == 0 || temp->next->val == 0)\n            {\n                temp = temp->next;\n            }\n            else\n            {\n                temp -> val += temp->next->val;\n                del(temp);\n            }   \n        }\n        \n        ListNode* dummy = new ListNode(-1);\n        dummy->next = head;\n        temp = dummy;\n        while(temp!=NULL)\n        {\n            if(temp->next->val == 0)\n            {\n                del(temp);\n            }\n            temp = temp->next;\n        }\n        return dummy->next;\n    }\n};\n```\n\nThe approach is simple firstly sum the non zero nodes then eliminate the zeros. You can try to short it up via deleting 0 in first loop but it will look complex that is why I am leaving it here. Peace :)
['Linked List', 'C', 'C++']