✅ MERGE NODES IN BETWEEN ZEROS ✅ Beats 100%
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n# Co
# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     int val;\n *     ListNode next;\n *     ListNode() {}\n *     ListNode(int val) { this.val = val; }\n *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n    public ListNode mergeNodes(ListNode head) {\n        // Create two pointers\n        ListNode temp = head;\n        ListNode p = head.next;\n\n        // Run a loop till p == null\n        while(p != null) {\n            // create a variable to store the sum of node values between two zeros\n            int sum = 0;\n\n            // run a loop to sum values of nodes\n            while(p.val != 0) {\n                sum += p.val;\n                p = p.next;\n            }\n\n            // create newNode with sum value and add it to linked list\n            ListNode newNode = new ListNode(sum);\n            temp.next = newNode;\n            temp = temp.next;\n            \n            p = p.next;\n        }\n        // return head.next because we don\'t need first node of head which is zero\n        return head.next;\n    }\n}\n```
['Java']