Skip to content

Commit cbec484

Browse files
Merge pull request #835 from changchanghwang/main
[Arthur] week 4
2 parents 2c52d14 + eaf95a6 commit cbec484

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)