Simple C++ Solution
IntuitionDo summation to calculate the sum between zeroes and when a zero is encountered save this sum and then reset the sum.Approach
Starting with a dummy nod
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Do summation to calculate the sum between zeroes and when a zero is encountered save this sum and then reset the sum.

# Approach
<!-- Describe your approach to solving the problem. -->
* Starting with a dummy node (newHead), a pointer (newTail) is used to build the result list and a variable c to accumulate the sum of node values. 
* As the list is traversed, the sum is calculated until a zero node is encountered. 
* At this point, a new node with the accumulated sum is appended to the result list, and the sum is reset. T
* The dummy node simplifies managing the result list, returning newHead->next as the final output.



# Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(m) where m in number of segments present between zeroes.
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* mergeNodes(ListNode* head) {
        
        ListNode* temp = head, *newHead = new ListNode(0), *newTail = newHead;
        int c=0;

        while(temp != nullptr)
        {
            if(temp -> val == 0 && temp != head)
            {
                ListNode* newNode = new ListNode(c);
                newTail -> next = newNode;
                newTail = newTail -> next;
                c = 0;
            }
            else
            {
                c += temp -> val;
            }
            temp = temp -> next;
        }

        return newHead -> next;   
    }
};
```
['C++']