[Python] Simple solution | 99.97 faster | O(n) Time | O(1) space
Understanding:\nIterate through the list and keep adding the digits till you find a \'0\'. When you find a \'0\' add it to the list and repeat the process again
Understanding:\nIterate through the list and keep adding the digits till you find a \'0\'. When you find a \'0\' add it to the list and repeat the process again.\n\nAlgorithm:\n- Initialize sum = 0, pointer 1 to the head and pointer 2 to the next element in the list.\n- Loop through the list till pointer 2 reaches the end of the list.\n- In the loop, if pointer 2\'s value is 0 then, make pointer 1 move to the next list item and give it the value of the current sum. Re-initialize the sum to 0.\n- Else keep adding pointer 2\'s value to the current sum.\n- Increment pointer 2.\n- When pointer 2 reaches the end of the list, make pointer 1\'s next None. (We store the sum values in the same list to make it memory efficient)\n- Return the second element on the list. (First element is a 0)\n\n```\nclass Solution:\n    def mergeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]:\n        ptr1 = head\n        ptr2 = head.next\n        s = 0\n        while ptr2:\n            if ptr2.val == 0:\n                ptr1 = ptr1.next\n                ptr1.val=s\n                s=0\n            else:\n                s+=ptr2.val\n            ptr2 = ptr2.next\n        ptr1.next=None\n        return head.next\n```
['Linked List', 'Two Pointers', 'Python']