Time O(n) 90% Beats, Space o(1) 98% Beats || c++
\nclass Solution {\npublic:\n    ListNode* mergeNodes(ListNode* head) {\n        ListNode*p = head,*q = head;\n        ListNode* ans = q;\n        int x = 0;\n 
```\nclass Solution {\npublic:\n    ListNode* mergeNodes(ListNode* head) {\n        ListNode*p = head,*q = head;\n        ListNode* ans = q;\n        int x = 0;\n        while(p!= NULL){\n            x = 0;\n            p = p->next;\n            if(!p)break;\n            while(p->val!=0){\n                x += p->val;\n                p = p->next;\n            }\n            // p = p->next;\n            q->val = x;\n            ans = q;\n            q = q->next;\n        }\n        ans->next = NULL;\n        return head;\n    }\n};\n```
['Linked List', 'C', 'C++']