[Java/Python 3] One pass two pointers, copy sum to 0 nodes.
Use zero nodes to store the sum of merged nodes, remove the last zero node, which is unused.\n\n1. Use prev to connect and move among all zero nodes;\n2. Use he
Use zero nodes to store the sum of merged nodes, remove the last zero node, which is unused.\n\n1. Use `prev` to connect and move among all zero nodes;\n2. Use `head` to traverse nodes between zero nodes, and add their values to the previous zero node;\n3. Always use `prev` point to the node right before current zero node, hence we can remove the last zero node easily.\n\n```java\n    public ListNode mergeNodes(ListNode head) {\n        ListNode dummy = new ListNode(Integer.MIN_VALUE), prev = dummy;\n        while (head != null && head.next != null) {\n            prev.next = head; // prev connects next 0 node.\n            head = head.next; // head forward to a non-zero node.\n            while (head != null && head.val != 0) { // traverse all non-zero nodes between two zero nodes.\n                prev.next.val += head.val; // add current value to the previous zero node.\n                head = head.next; // forward one step.\n            }\n            prev = prev.next; // prev point to the summation node (initially 0).\n        }\n        prev.next = null; // cut off last 0 node.\n        return dummy.next;\n    }\n```\n```python\n    def mergeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]:\n        dummy = prev = ListNode(-math.inf)\n        while head and head.next:\n            prev.next = head\n            head = head.next\n            while head and head.val != 0:\n                prev.next.val += head.val\n                head = head.next\n            prev = prev.next\n        prev.next = None    \n        return dummy.next\n```\n\n**Analysis:**\n\nTime: `O(n)`, extra space: `O(1)`, where `n` is the number of nodes.
['Java', 'Python3']