|
| 1 | +{ |
| 2 | + "problem_name": "binary_tree_level_order_traversal", |
| 3 | + "solution_class_name": "Solution", |
| 4 | + "problem_number": "102", |
| 5 | + "problem_title": "Binary Tree Level Order Traversal", |
| 6 | + "difficulty": "Medium", |
| 7 | + "topics": "Tree, Breadth-First Search, Binary Tree", |
| 8 | + "tags": ["grind-75"], |
| 9 | + "readme_description": "Given the `root` of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).", |
| 10 | + "readme_examples": [ |
| 11 | + { |
| 12 | + "content": "\n\n```\nInput: root = [3,9,20,null,null,15,7]\nOutput: [[3],[9,20],[15,7]]\n```" |
| 13 | + }, |
| 14 | + { "content": "```\nInput: root = [1]\nOutput: [[1]]\n```" }, |
| 15 | + { "content": "```\nInput: root = []\nOutput: []\n```" } |
| 16 | + ], |
| 17 | + "readme_constraints": "- The number of nodes in the tree is in the range [0, 2000]\n- -1000 <= Node.val <= 1000", |
| 18 | + "readme_additional": "", |
| 19 | + "solution_imports": "from leetcode_py import TreeNode", |
| 20 | + "solution_methods": [ |
| 21 | + { |
| 22 | + "name": "level_order", |
| 23 | + "parameters": "root: TreeNode | None", |
| 24 | + "return_type": "list[list[int]]", |
| 25 | + "dummy_return": "[]" |
| 26 | + } |
| 27 | + ], |
| 28 | + "test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom leetcode_py import TreeNode\nfrom .solution import Solution", |
| 29 | + "test_class_name": "BinaryTreeLevelOrderTraversal", |
| 30 | + "test_helper_methods": [ |
| 31 | + { "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" } |
| 32 | + ], |
| 33 | + "test_methods": [ |
| 34 | + { |
| 35 | + "name": "test_level_order", |
| 36 | + "parametrize": "root_list, expected", |
| 37 | + "parametrize_typed": "root_list: list[int | None], expected: list[list[int]]", |
| 38 | + "test_cases": "[([3, 9, 20, None, None, 15, 7], [[3], [9, 20], [15, 7]]), ([1], [[1]]), ([], []), ([1, 2, 3, 4, 5, 6, 7], [[1], [2, 3], [4, 5, 6, 7]]), ([1, 2, None, 3, None, 4, None, 5], [[1], [2], [3], [4], [5]])]", |
| 39 | + "body": "root = TreeNode.from_list(root_list) if root_list else None\nresult = self.solution.level_order(root)\nassert result == expected" |
| 40 | + } |
| 41 | + ], |
| 42 | + "playground_imports": "from solution import Solution\nfrom leetcode_py import TreeNode", |
| 43 | + "playground_test_case": "# Example test case\nroot_list = [3, 9, 20, None, None, 15, 7]\nroot = TreeNode.from_list(root_list)\nexpected = [[3], [9, 20], [15, 7]]", |
| 44 | + "playground_execution": "result = Solution().level_order(root)\nresult", |
| 45 | + "playground_assertion": "assert result == expected" |
| 46 | +} |
0 commit comments