Traverse and Accumulate Node Values Between Zeros, Simple Solution.
Intuition\nThe task requires us to sum up the values between nodes with the value 0 and create new nodes with these summed values. Using a dummy node simplifies
# Intuition\nThe task requires us to sum up the values between nodes with the value 0 and create new nodes with these summed values. Using a dummy node simplifies the handling of edge cases and allows for straightforward traversal and linking of the new nodes.\n\n# Approach\n1. Dummy Node: Start with a dummy node that will help in easily building the result list.\n2. Traverse and Accumulate: Traverse the list from the first node after the initial zero. Accumulate the values until a zero is encountered.\n3. Create New Nodes: When a zero is found, create a new node with the accumulated sum and link it to the current node in the result list.\n4. Reset and Continue: Reset the sum and continue the process until the end of the list.\n\n# Complexity\n- Time complexity:\nO(n) A single traversal through the given linked list.\n\n- Space complexity:\nO(1) We have not used any extra space.\n\n# Code\n```\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode* mergeNodes(ListNode* head) {\n        ListNode* dummy = new ListNode(0);\n        ListNode* current = dummy;\n        \n        ListNode* temp = head->next;\n        int sum = 0;\n        \n        while (temp != nullptr) {\n            if (temp->val != 0) {\n                sum += temp->val;\n            } else {\n                if (sum != 0) {\n                    current->next = new ListNode(sum);\n                    current = current->next;\n                    sum = 0;\n                }\n            }\n            temp = temp->next;\n        }\n        \n        return dummy->next;\n    }\n};\n```
['Linked List', 'Simulation', 'C++']