Java | Iterative | O(n) time | 12 lines | Clean code
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\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(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n  public ListNode mergeNodes(ListNode head) {\n    var sum = 0;\n    var dummyHead = new ListNode();\n    var prev = dummyHead;\n\n    for (var p = head.next; p != null; p = p.next) {\n      if (p.val == 0) {\n        var node = new ListNode(sum);\n        prev.next = node;\n        prev = node;\n        sum = 0;\n        continue;\n      }\n      sum += p.val;\n    }\n    return dummyHead.next;\n  }\n}\n```\nIf you like my solution, please upvote it!
['Linked List', 'Simulation', 'Java']