File tree 1 file changed +15
-14
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +15
-14
lines changed Original file line number Diff line number Diff line change 9
9
* The new list should be made by splicing together the nodes of the first two lists.*/
10
10
11
11
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
+ }
26
27
}
27
28
}
28
29
You can’t perform that action at this time.
0 commit comments