Skip to content

Commit 1c4fa72

Browse files
authored
Create 1669-merge-in-between-linked-lists.kt
1 parent 38d2104 commit 1c4fa72

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
fun mergeInBetween(list1: ListNode?, a: Int, b: Int, list2: ListNode?): ListNode? {
3+
var curr = list1
4+
var i = 0
5+
while (i < a - 1) {
6+
curr = curr?.next
7+
i++
8+
}
9+
10+
var head = curr
11+
while (i <= b) {
12+
curr = curr?.next
13+
i++
14+
}
15+
head?.next = list2
16+
17+
var list2 = list2
18+
while (list2?.next != null)
19+
list2 = list2?.next
20+
list2?.next = curr
21+
return list1
22+
}
23+
}

0 commit comments

Comments
 (0)