diff --git a/go/merge-nodes-in-between-zeros.go b/go/merge-nodes-in-between-zeros.go new file mode 100644 index 0000000..fcd8afa --- /dev/null +++ b/go/merge-nodes-in-between-zeros.go @@ -0,0 +1,18 @@ +package main + +func mergeNodes(head *ListNode) *ListNode { + head = head.Next + if head == nil { + return nil + } + + node := head.Next + for node.Val != 0 { + head.Val += node.Val + node = node.Next + } + + head.Next = mergeNodes(node) + + return head +}