Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 79d82cf

Browse files
Add Solution2.go for 0021.Merge Two Sorted Lists
1 parent 29be45a commit 79d82cf

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {
2+
if l1 == nil {
3+
return l2
4+
}
5+
if l2 == nil {
6+
return l1
7+
}
8+
if l1.Val < l2.Val {
9+
l1.Next = mergeTwoLists(l1.Next, l2)
10+
return l1
11+
} else {
12+
l2.Next = mergeTwoLists(l1, l2.Next)
13+
return l2
14+
}
15+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /