Skip to content

Commit f1c5a62

Browse files
author
Li Beibei
committed
021 fix: if one of the given lists is null
1 parent a87b050 commit f1c5a62

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

note/021/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class Solution {
3131
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
3232
ListNode head = new ListNode(0);
3333
ListNode temp = head;
34+
if (l1 == null) {
35+
return l2;
36+
} else if (l2 == null) {
37+
return l1;
38+
}
3439
while (l1 != null && l2 != null) {
3540
if (l1.val < l2.val) {
3641
temp.next = l1;

0 commit comments

Comments
 (0)