Skip to content

Commit a229b58

Browse files
refactor 21
1 parent 6fdb918 commit a229b58

File tree

1 file changed

+15
-14
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+15
-14
lines changed

src/main/java/com/fishercoder/solutions/_21.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@
99
* The new list should be made by splicing together the nodes of the first two lists.*/
1010

1111
public class _21 {
12-
13-
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
14-
if (l1 == null) {
15-
return l2;
16-
}
17-
if (l2 == null) {
18-
return l1;
19-
}
20-
if (l1.val < l2.val) {
21-
l1.next = mergeTwoLists(l1.next, l2);
22-
return l1;
23-
} else {
24-
l2.next = mergeTwoLists(l1, l2.next);
25-
return l2;
12+
public static class Solution1 {
13+
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
14+
if (l1 == null) {
15+
return l2;
16+
}
17+
if (l2 == null) {
18+
return l1;
19+
}
20+
if (l1.val < l2.val) {
21+
l1.next = mergeTwoLists(l1.next, l2);
22+
return l1;
23+
} else {
24+
l2.next = mergeTwoLists(l1, l2.next);
25+
return l2;
26+
}
2627
}
2728
}
2829

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy