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