Skip to content

Commit 9b1b3ef

Browse files
refactor 21
1 parent 9380203 commit 9b1b3ef

File tree

1 file changed

+12
-1
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,21 @@
66
* 21. Merge Two Sorted Lists
77
*
88
* Merge two sorted linked lists and return it as a new list.
9-
* The new list should be made by splicing together the nodes of the first two lists.*/
9+
* The new list should be made by splicing together the nodes of the first two lists.
10+
*
11+
* Example:
12+
* Input: 1->2->4, 1->3->4
13+
* Output: 1->1->2->3->4->4
14+
*
15+
* */
1016

1117
public class _21 {
1218
public static class Solution1 {
19+
/**
20+
* recursive solution
21+
* Time: O(m+n)
22+
* Space: O(m+n)
23+
* */
1324
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
1425
if (l1 == null) {
1526
return l2;

0 commit comments

Comments
 (0)