Python Solution 🔥
Intuition\nTraverse the linked list and accumulate the values between the zeros. Each time a zero is encountered, the accumulated sum (if any) should be added t
### Intuition\nTraverse the linked list and accumulate the values between the zeros. Each time a zero is encountered, the accumulated sum (if any) should be added to a new linked list as a node. This ensures that the modified list contains only the sum of nodes between zeros and no zeros themselves.\n\n### Approach\n\n1. **Initialization**:\n   - Create a dummy node to serve as the starting point of the new linked list. This helps in easily managing the head of the result list.\n   - Use a pointer (`current`) to keep track of the last node in the new list.\n   - Initialize `current_sum` to accumulate the values between zeros.\n\n2. **Skip Initial Zero**:\n   - Move the head pointer to `head.next` to skip the initial zero.\n\n3. **Traverse and Accumulate**:\n   - Traverse the list while the head is not null.\n   - If the value is zero, check if `current_sum` is greater than zero:\n     - If yes, create a new node with `current_sum`, link it to the result list, and reset `current_sum` to zero.\n   - If the value is not zero, add the value to `current_sum`.\n   - Move the head pointer to the next node.\n\n4. **Return Result**:\n   - Return `dummy.next` as the head of the modified list since `dummy` was a placeholder.\n\n### Complexity\n\n- **Time Complexity**: \n  - The time complexity is \\(O(n)\\), where \\(n\\) is the number of nodes in the linked list. This is because we traverse each node exactly once.\n\n- **Space Complexity**: \n  - The space complexity is \\(O(1)\\) for the extra space used, as we are not using any additional data structures that grow with the input size. However, the new linked list itself requires space proportional to the number of segments between zeros, which is also \\(O(n)\\) in the worst case.\n\n# Code\n```\n# Definition for singly-linked list.\n# class ListNode:\n#     def __init__(self, val=0, next=None):\n#         self.val = val\n#         self.next = next\nclass Solution:\n    def mergeNodes(self, head: ListNode) -> ListNode:\n        # Initialize the dummy node for the new linked list.\n        dummy = ListNode(0)\n        current = dummy\n        \n        # Skip the initial 0\n        head = head.next\n        \n        # To hold the current sum\n        current_sum = 0\n        \n        while head is not None:\n            if head.val == 0:\n                # We encountered a zero, finalize the current sum\n                if current_sum > 0:\n                    current.next = ListNode(current_sum)\n                    current = current.next\n                # Reset the sum for the next segment\n                current_sum = 0\n            else:\n                # Add value to the current sum\n                current_sum += head.val\n            \n            # Move to the next node\n            head = head.next\n        \n        return dummy.next\n \n```
['Linked List', 'Python3']