Skip to content

Commit 4d20a70

Browse files
authored
Merge pull request #3358 from xtommas/main
Create 1669-merge-in-between-linked-lists.go
2 parents 894619e + 4b0f977 commit 4d20a70

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Diff for: go/1669-merge-in-between-linked-lists.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* type ListNode struct {
4+
* Val int
5+
* Next *ListNode
6+
* }
7+
*/
8+
func mergeInBetween(list1 *ListNode, a int, b int, list2 *ListNode) *ListNode {
9+
curr := list1
10+
i := 0
11+
for i < a-1 {
12+
curr = curr.Next
13+
i++
14+
}
15+
16+
head := curr
17+
for i <= b {
18+
curr = curr.Next
19+
i++
20+
}
21+
head.Next = list2
22+
23+
for list2.Next != nil {
24+
list2 = list2.Next
25+
}
26+
27+
list2.Next = curr
28+
29+
return list1
30+
}

0 commit comments

Comments
 (0)