|
| 1 | +{ |
| 2 | + "problem_name": "merge_two_sorted_lists", |
| 3 | + "solution_class_name": "Solution", |
| 4 | + "problem_number": "21", |
| 5 | + "problem_title": "Merge Two Sorted Lists", |
| 6 | + "difficulty": "Easy", |
| 7 | + "topics": "Linked List, Recursion", |
| 8 | + "tags": ["grind-75"], |
| 9 | + "readme_description": "You are given the heads of two sorted linked lists `list1` and `list2`.\n\nMerge the two lists into one **sorted** list. The list should be made by splicing together the nodes of the first two lists.\n\nReturn *the head of the merged linked list*.", |
| 10 | + "readme_examples": [ |
| 11 | + { |
| 12 | + "content": "\n\n```\nInput: list1 = [1,2,4], list2 = [1,3,4]\nOutput: [1,1,2,3,4,4]\n```" |
| 13 | + }, |
| 14 | + { "content": "```\nInput: list1 = [], list2 = []\nOutput: []\n```" }, |
| 15 | + { "content": "```\nInput: list1 = [], list2 = [0]\nOutput: [0]\n```" } |
| 16 | + ], |
| 17 | + "readme_constraints": "- The number of nodes in both lists is in the range `[0, 50]`.\n- `-100 <= Node.val <= 100`\n- Both `list1` and `list2` are sorted in **non-decreasing** order.", |
| 18 | + "readme_additional": "", |
| 19 | + "solution_imports": "from leetcode_py import ListNode", |
| 20 | + "solution_methods": [ |
| 21 | + { |
| 22 | + "name": "merge_two_lists", |
| 23 | + "parameters": "list1: ListNode | None, list2: ListNode | None", |
| 24 | + "return_type": "ListNode | None", |
| 25 | + "dummy_return": "None" |
| 26 | + } |
| 27 | + ], |
| 28 | + "test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom leetcode_py import ListNode\nfrom .solution import Solution", |
| 29 | + "test_class_name": "MergeTwoSortedLists", |
| 30 | + "test_helper_methods": [ |
| 31 | + { "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" } |
| 32 | + ], |
| 33 | + "test_methods": [ |
| 34 | + { |
| 35 | + "name": "test_merge_two_lists", |
| 36 | + "parametrize": "list1_vals, list2_vals, expected_vals", |
| 37 | + "parametrize_typed": "list1_vals: list[int], list2_vals: list[int], expected_vals: list[int]", |
| 38 | + "test_cases": "[([1, 2, 4], [1, 3, 4], [1, 1, 2, 3, 4, 4]), ([], [], []), ([], [0], [0]), ([1], [2], [1, 2]), ([2], [1], [1, 2])]", |
| 39 | + "body": "list1 = ListNode.from_list(list1_vals)\nlist2 = ListNode.from_list(list2_vals)\nexpected = ListNode.from_list(expected_vals)\nresult = self.solution.merge_two_lists(list1, list2)\nassert result == expected" |
| 40 | + } |
| 41 | + ], |
| 42 | + "playground_imports": "from solution import Solution\nfrom leetcode_py import ListNode", |
| 43 | + "playground_test_case": "# Example test case\nlist1_vals = [1, 2, 4]\nlist2_vals = [1, 3, 4]\nexpected_vals = [1, 1, 2, 3, 4, 4]", |
| 44 | + "playground_execution": "list1 = ListNode.from_list(list1_vals)\nlist2 = ListNode.from_list(list2_vals)\nresult = Solution().merge_two_lists(list1, list2)\nresult", |
| 45 | + "playground_assertion": "expected = ListNode.from_list(expected_vals)\nassert result == expected" |
| 46 | +} |
0 commit comments