1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-09 15:59:06 +01:00

go: add «2181. Merge Nodes in Between Zeros»

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-07-04 13:51:06 +02:00
parent bcabf01c65
commit a837889497
Signed by: mfocko
SSH key fingerprint: SHA256:5YXD7WbPuK60gxnG6DjAwJiS9+swoWj33/HFu8g8JVo

View file

@ -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
}