✅Easiest 3 Step Cpp / Java / Py / JS Solution | Normal Approach🏆|  No Advance
\n### C++\n\nclass Solution {\npublic:\n    ListNode* mergeNodes(ListNode* head) {\n        // Initialize a dummy node to help with edge cases\n        ListNode
\n### C++\n```\nclass Solution {\npublic:\n    ListNode* mergeNodes(ListNode* head) {\n        // Initialize a dummy node to help with edge cases\n        ListNode dummy(0);\n        ListNode* tail = &dummy;\n        \n        ListNode* current = head->next; // Start from the node after the initial zero\n        int sum = 0;\n\n        while (current != nullptr) {\n            if (current->val == 0) {\n                // When we encounter a zero, it signifies the end of a segment\n                if (sum != 0) {\n                    // Create a new node with the sum and add it to the result list\n                    tail->next = new ListNode(sum);\n                    tail = tail->next;\n                    sum = 0; // Reset the sum for the next segment\n                }\n            } else {\n                // Add the current node\'s value to the sum\n                sum += current->val;\n            }\n            current = current->next;\n        }\n\n        return dummy.next; // The first node in the dummy list is the start of the result list\n    }\n};\n```\n### Java\n```\nclass Solution {\n    public ListNode mergeNodes(ListNode head) {\n        ListNode dummy = new ListNode(0); // Dummy node to simplify list construction\n        ListNode currentNew = dummy; // Pointer to construct new list\n        ListNode currentOld = head.next; // Start from the node after the initial zero\n\n        int sum = 0;\n        \n        while (currentOld != null) {\n            if (currentOld.val == 0) {\n                // When we hit a zero, we need to create a new node with the sum if sum is non-zero\n                if (sum != 0) {\n                    currentNew.next = new ListNode(sum);\n                    currentNew = currentNew.next;\n                    sum = 0; // Reset sum for the next segment\n                }\n            } else {\n                // Accumulate the sum of values between zeros\n                sum += currentOld.val;\n            }\n            currentOld = currentOld.next;\n        }\n\n        return dummy.next; // The first node in the dummy list is the start of the result list\n    }\n}\n\n```\n\n### Python3\n```\nclass Solution:\n    def mergeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]:\n        dummy = ListNode(0) # Dummy node to simplify list construction\n        currentNew = dummy # Pointer to construct new list\n        currentOld = head.next # Start from the node after the initial zero\n\n        sum = 0\n        \n        while currentOld is not None:\n            if currentOld.val == 0:\n                # When we hit a zero, we need to create a new node with the sum if sum is non-zero\n                if sum != 0:\n                    currentNew.next = ListNode(sum)\n                    currentNew = currentNew.next\n                    sum = 0 # Reset sum for the next segment\n            else:\n                # Accumulate the sum of values between zeros\n                sum += currentOld.val\n            currentOld = currentOld.next\n\n        return dummy.next # The first node in the dummy list is the start of the result list\n```\n### JavaScript\n```\n/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n *     this.val = (val===undefined ? 0 : val)\n *     this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar mergeNodes = function(head) {\n    let dummy = new ListNode(0); // Dummy node to simplify list construction\n    let currentNew = dummy; // Pointer to construct new list\n    let currentOld = head.next; // Start from the node after the initial zero\n\n    let sum = 0;\n    \n    while (currentOld !== null) {\n        if (currentOld.val === 0) {\n            // When we hit a zero, we need to create a new node with the sum if sum is non-zero\n            if (sum !== 0) {\n                currentNew.next = new ListNode(sum);\n                currentNew = currentNew.next;\n                sum = 0; // Reset sum for the next segment\n            }\n        } else {\n            // Accumulate the sum of values between zeros\n            sum += currentOld.val;\n        }\n        currentOld = currentOld.next;\n    }\n\n    return dummy.next; // The first node in the dummy list is the start of the result list\n};\n\n```\n#### STAY COOL STAY DISCIPLINED..\n\n![image](https://assets.leetcode.com/users/images/ad294515-01e3-4704-a668-9bcc5b0e822c_1717851160.1975598.gif)
['Linked List', 'C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']