BEST C++ solution || Simple approach || Beats 100% in time and memory !!
\n\n# Code\n\n// SC - O(N)\nclass Solution {\npublic:\n    ListNode* mergeNodes(ListNode* head) {\n        int sum = 0;\n        ListNode *ans = new ListNode(-1
\n\n# Code\n```\n// SC - O(N)\nclass Solution {\npublic:\n    ListNode* mergeNodes(ListNode* head) {\n        int sum = 0;\n        ListNode *ans = new ListNode(-1), *temp = ans;\n        ListNode *curr = head->next;\n\n        while(curr!= NULL){\n            while(curr->val != 0){\n                sum += curr->val;\n                curr = curr->next;\n            }\n            ListNode *n = new ListNode(sum);\n            temp->next = n;\n            temp = n;\n            sum = 0;\n            curr = curr->next;\n        }\n\n        return ans->next;\n    }\n};\n\n// SC - O(1)\nclass Solution {\npublic:\n    ListNode* mergeNodes(ListNode* head) {\n        head = head->next;\n        ListNode *start = head;\n\n        while(start!= NULL){\n            ListNode *end = start;\n            int sum = 0;\n            while(end->val != 0){\n                sum += end->val;\n                end = end->next;\n            }\n            start->val = sum;\n            start->next = end->next;\n            start = start->next;\n        }\n\n        return head;\n    }\n};\n```
['Linked List', 'Two Pointers', 'Simulation', 'C++']