Simple Explanation with Dummy Node and Previous Pointer.
Intuition\nThe Intution here is just that you have to look for nodes with zeros and merge the other nodes into those zero node.\nHere is one exception that need
# Intuition\n*The Intution here is just that you have to look for nodes with zeros and merge the other nodes into those zero node.\nHere is one exception that needs to be handled the last node which is explained below.*\n\n# Approach\n1. Create a dummy node.\n2. Point that dummy node to head.\n3. Iterate from dummy node till end & check if next value is 0.\n4. If next is 0 then simply go to next node else add the value from next node to current node and set pointer of current node to next to next node.\n5. Store the cur node to a different variable before going to next node for skipping the last 0.\n6. At last return the head.\n\n# Complexity\n\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```python []\n# Definition for singly-linked list.\n# class ListNode:\n#     def __init__(self, val=0, next=None):\n#         self.val = val\n#         self.next = next\nclass Solution:\n    def mergeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]:\n        \n        dummy = ListNode()  # dummy node\n        dummy.next = head\n        cur = dummy\n\n        while cur.next:\n            prev = cur      # prev node before cur to skip last 0\n            if cur.next.val == 0:\n                cur = cur.next\n            if cur.next:\n                cur.val += cur.next.val\n                cur.next = cur.next.next\n        prev.next = None    # setting last 0 node to none\n        return head \n```\n```javascript []\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();\n    dummy.next = head;\n    let cur = dummy;\n    let prev;\n    while (cur.next){\n        prev = cur;\n        if (cur.next.val === 0){\n            cur = cur.next;\n        }\n        if (cur.next){\n            cur.val += cur.next.val\n            cur.next = cur.next.next\n        }\n    }\n    prev.next = null;\n    return head;\n};\n```\n
['Linked List', 'Simulation', 'TypeScript', 'Python3', 'JavaScript']