|
| 1 | +{ |
| 2 | + "problem_name": "same_tree", |
| 3 | + "solution_class_name": "Solution", |
| 4 | + "problem_number": "100", |
| 5 | + "problem_title": "Same Tree", |
| 6 | + "difficulty": "Easy", |
| 7 | + "topics": "Tree, Depth-First Search, Breadth-First Search, Binary Tree", |
| 8 | + "_tags": { "list": ["blind-75"] }, |
| 9 | + "readme_description": "Given the roots of two binary trees `p` and `q`, write a function to check if they are the same or not.\n\nTwo binary trees are considered the same if they are structurally identical, and the nodes have the same value.", |
| 10 | + "_readme_examples": { |
| 11 | + "list": [ |
| 12 | + { |
| 13 | + "content": "\n\n```\nInput: p = [1,2,3], q = [1,2,3]\nOutput: true\n```" |
| 14 | + }, |
| 15 | + { |
| 16 | + "content": "\n\n```\nInput: p = [1,2], q = [1,null,2]\nOutput: false\n```" |
| 17 | + }, |
| 18 | + { |
| 19 | + "content": "\n\n```\nInput: p = [1,2,1], q = [1,1,2]\nOutput: false\n```" |
| 20 | + } |
| 21 | + ] |
| 22 | + }, |
| 23 | + "readme_constraints": "- The number of nodes in both trees is in the range [0, 100].\n- -10^4 <= Node.val <= 10^4", |
| 24 | + "readme_additional": "", |
| 25 | + "helpers_imports": "from leetcode_py import TreeNode", |
| 26 | + "helpers_content": "", |
| 27 | + "helpers_run_name": "is_same_tree", |
| 28 | + "helpers_run_signature": "(solution_class: type, p_list: list[int | None], q_list: list[int | None])", |
| 29 | + "helpers_run_body": " p = TreeNode[int].from_list(p_list)\n q = TreeNode[int].from_list(q_list)\n implementation = solution_class()\n return implementation.is_same_tree(p, q)", |
| 30 | + "helpers_assert_name": "is_same_tree", |
| 31 | + "helpers_assert_signature": "(result: bool, expected: bool) -> bool", |
| 32 | + "helpers_assert_body": " assert result == expected\n return True", |
| 33 | + "solution_imports": "from leetcode_py import TreeNode", |
| 34 | + "solution_contents": "", |
| 35 | + "solution_class_content": "", |
| 36 | + "test_imports": "import pytest\nfrom leetcode_py import logged_test\nfrom .helpers import assert_is_same_tree, run_is_same_tree\nfrom .solution import Solution", |
| 37 | + "test_content": "", |
| 38 | + "test_class_name": "SameTree", |
| 39 | + "test_class_content": " def setup_method(self):\n self.solution = Solution()", |
| 40 | + "_solution_methods": { |
| 41 | + "list": [ |
| 42 | + { |
| 43 | + "name": "is_same_tree", |
| 44 | + "signature": "(self, p: TreeNode[int] | None, q: TreeNode[int] | None) -> bool", |
| 45 | + "body": " # TODO: Implement is_same_tree\n return False" |
| 46 | + } |
| 47 | + ] |
| 48 | + }, |
| 49 | + "_test_helper_methods": { |
| 50 | + "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] |
| 51 | + }, |
| 52 | + "_test_methods": { |
| 53 | + "list": [ |
| 54 | + { |
| 55 | + "name": "test_is_same_tree", |
| 56 | + "signature": "(self, p_list: list[int | None], q_list: list[int | None], expected: bool)", |
| 57 | + "parametrize": "p_list, q_list, expected", |
| 58 | + "test_cases": "[([1, 2, 3], [1, 2, 3], True), ([1, 2], [1, None, 2], False), ([1, 2, 1], [1, 1, 2], False), ([], [], True), ([1], [1], True), ([1], [2], False), ([1, None, 2], [1, 2], False), ([1, 2, 3, 4, 5], [1, 2, 3, 4, 5], True), ([1, 2, 3, 4, 5], [1, 2, 3, 4, 6], False), ([1, 2, 3, None, 4], [1, 2, 3, None, 4], True), ([1, 2, 3, None, 4], [1, 2, 3, 4, None], False)]", |
| 59 | + "body": " result = run_is_same_tree(Solution, p_list, q_list)\n assert_is_same_tree(result, expected)" |
| 60 | + } |
| 61 | + ] |
| 62 | + }, |
| 63 | + "playground_imports": "from helpers import run_is_same_tree, assert_is_same_tree\nfrom solution import Solution\nfrom leetcode_py import TreeNode", |
| 64 | + "playground_setup": "# Example test case\np_list: list[int | None] = [1, 2, 3]\nq_list: list[int | None] = [1, 2, 3]\nexpected = True", |
| 65 | + "playground_run": "result = run_is_same_tree(Solution, p_list, q_list)\nresult", |
| 66 | + "playground_assert": "assert_is_same_tree(result, expected)" |
| 67 | +} |
0 commit comments