Skip to content

Commit 4d20a70

Browse files
authored
Merge pull request neetcode-gh#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
Lines changed: 30 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy