Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n``` javascript []\nvar mergeNodes = function(head) {\n    let ptr = head;\n    let prev = null;\n    while(ptr) {\n        let temp = ptr.val;\n        if(temp == 0 && !ptr.next) {\n            prev.next = null;\n            break;\n        } else if(temp == 0) {\n            if(prev) prev.next = ptr;\n            prev = ptr;\n        } else {\n            prev.val += temp;\n        }\n        ptr = ptr.next;\n    }\n    return head;\n};\n```\n``` cpp []\nclass Solution {\npublic:\n    ListNode* mergeNodes(ListNode* head) {\n        ListNode* ptr = head;\n        ListNode* prev = nullptr;\n        while(ptr) {\n            int temp = ptr->val;\n            if(temp == 0 && !ptr->next) {\n                prev->next = nullptr;\n                break;\n            } else if(temp == 0) {\n                if(prev) prev->next = ptr;\n                prev = ptr;\n            } else {\n                prev->val += temp;\n            }\n            ptr = ptr->next;\n        }\n        return head;\n    }\n};\n```\n``` python3 []\nclass Solution:\n    def mergeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]:\n        ptr = head\n        prev = None\n        while ptr:\n            temp = ptr.val\n            if temp == 0 and not ptr.next:\n                prev.next = None\n            elif temp == 0:\n                if prev: prev.next = ptr\n                prev = ptr\n            else:\n                prev.val += temp\n            ptr = ptr.next\n        return head\n```\n
['Linked List', 'Simulation', 'C++', 'Python3', 'JavaScript']