<jupyter_start><jupyter_text>Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Example 1:    Input:     1         1              / \       / \             2   3     2   3            [1,2,3],   [1,2,3]    Output: trueExample 2:    Input:     1         1              /           \             2             2            [1,2],     [1,null,2]    Output: falseExample 3:    Input:     1         1              / \       / \             2   1     1   2            [1,2,1],   [1,1,2]    Output: false<jupyter_code># Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def isSameTree(self, p: TreeNode, q: TreeNode) -> bool:
        if not p and not q:
            return True
        if p and q:
            return p.val == q.val and self.isSameTree(p.left,q.left) and self.isSameTree(p.right,q.right)
        return False
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def isSameTree(self, p, q):
        '''
        :param p: TreeNode
        :param q: TreeNode
        :return: bool
        '''
        # p and q are both empty
        if not p and not q:
            return True
        
        # one of p and q is not empty
        if not p or not q:
            return False
        
        # data included in p and q are not equal
        if p.val != q.val:
            return False
        
        # recursion, to decide the left subtree and right subtree
        return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08728046833422033, 'fraction_numerical': 0.018626929217668974, 'mean_word_length': 1.4133504492939666, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '249361', 'license': 'MIT', 'n_tokens_mistral': 567, 'n_tokens_neox': 558, 'n_words': 205, 'path': 'DSA/tree/SameTree.ipynb', 'repo_name': 'lance-lh/Data-Structures-and-Algorithms', 'size': '1879'}