Skip to content

Commit eaf95a6

Browse files
feat: merge two lists
1 parent 03ded85 commit eaf95a6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
type ListNode struct {
2+
Val int
3+
Next *ListNode
4+
}
5+
6+
func mergeTwoLists(list1 *ListNode, list2 *ListNode) *ListNode {
7+
if list1 == nil {
8+
return list2
9+
}
10+
if list2 == nil {
11+
return list1
12+
}
13+
14+
if list1.Val < list2.Val {
15+
list1.Next = mergeTwoLists(list1.Next, list2)
16+
return list1
17+
}
18+
list2.Next = mergeTwoLists(list1, list2.Next)
19+
return list2
20+
}

0 commit comments

Comments
 (0)