|
| 1 | +{ |
| 2 | + "problem_name": "reverse_linked_list", |
| 3 | + "solution_class_name": "Solution", |
| 4 | + "problem_number": "206", |
| 5 | + "problem_title": "Reverse Linked List", |
| 6 | + "difficulty": "Easy", |
| 7 | + "topics": "Linked List, Recursion", |
| 8 | + "tags": ["grind-75"], |
| 9 | + "readme_description": "Given the `head` of a singly linked list, reverse the list, and return the reversed list.", |
| 10 | + "readme_examples": [ |
| 11 | + { |
| 12 | + "content": "\n\n```\nInput: head = [1,2,3,4,5]\nOutput: [5,4,3,2,1]\n```" |
| 13 | + }, |
| 14 | + { |
| 15 | + "content": "\n\n```\nInput: head = [1,2]\nOutput: [2,1]\n```" |
| 16 | + }, |
| 17 | + { "content": "```\nInput: head = []\nOutput: []\n```" } |
| 18 | + ], |
| 19 | + "readme_constraints": "- The number of nodes in the list is the range `[0, 5000]`.\n- `-5000 <= Node.val <= 5000`", |
| 20 | + "readme_additional": "**Follow up:** A linked list can be reversed either iteratively or recursively. Could you implement both?", |
| 21 | + "solution_imports": "from leetcode_py import ListNode", |
| 22 | + "solution_methods": [ |
| 23 | + { |
| 24 | + "name": "reverse_list", |
| 25 | + "parameters": "head: ListNode[int] | None", |
| 26 | + "return_type": "ListNode[int] | None", |
| 27 | + "dummy_return": "None" |
| 28 | + } |
| 29 | + ], |
| 30 | + "test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom leetcode_py import ListNode\nfrom .solution import Solution", |
| 31 | + "test_class_name": "ReverseLinkedList", |
| 32 | + "test_helper_methods": [ |
| 33 | + { "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" } |
| 34 | + ], |
| 35 | + "test_methods": [ |
| 36 | + { |
| 37 | + "name": "test_reverse_list", |
| 38 | + "parametrize": "head_list, expected_list", |
| 39 | + "parametrize_typed": "head_list: list[int], expected_list: list[int]", |
| 40 | + "test_cases": "[([1, 2, 3, 4, 5], [5, 4, 3, 2, 1]), ([1, 2], [2, 1]), ([1], [1]), ([], []), ([1, 2, 3], [3, 2, 1]), ([1, 2, 3, 4], [4, 3, 2, 1]), ([-1, -2, -3], [-3, -2, -1]), ([0], [0]), ([5000, -5000], [-5000, 5000]), ([1, 1, 1], [1, 1, 1])]", |
| 41 | + "body": "head = ListNode.from_list(head_list)\nexpected = ListNode.from_list(expected_list)\nresult = self.solution.reverse_list(head)\nassert result == expected" |
| 42 | + } |
| 43 | + ], |
| 44 | + "playground_imports": "from leetcode_py import ListNode\nfrom solution import Solution", |
| 45 | + "playground_test_case": "# Example test case\nhead_list = [1, 2, 3, 4, 5]\nexpected_list = [5, 4, 3, 2, 1]\nhead = ListNode.from_list(head_list)\nexpected = ListNode.from_list(expected_list)", |
| 46 | + "playground_execution": "result = Solution().reverse_list(head)\nresult", |
| 47 | + "playground_assertion": "assert result == expected" |
| 48 | +} |
0 commit comments