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:
parent
bcabf01c65
commit
a837889497
1 changed files with 18 additions and 0 deletions
18
go/merge-nodes-in-between-zeros.go
Normal file
18
go/merge-nodes-in-between-zeros.go
Normal 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
|
||||
}
|
Loading…
Reference in a new issue