1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
LeetCode/go/merge-nodes-in-between-zeros.go
Matej Focko a837889497
go: add «2181. Merge Nodes in Between Zeros»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-07-04 13:51:06 +02:00

18 lines
243 B
Go

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
}