# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution(object):
def isSameTree(self, p, q):
"""
:type p: TreeNode
:type q: TreeNode
:rtype: bool
"""
# print(p)
# print(q)
def compare_trees(p_node, q_node, checkR):
if p_node and q_node:
# print(p_node.val, q_node.val)
if p_node.val != q_node.val:
# print("F1")
checkR.append(False)
if p_node.left and q_node.left:
compare_trees(p_node.left, q_node.left, checkR)
elif p_node.left or q_node.left:
# print("F2")
checkR.append(False)
if p_node.right and q_node.right:
compare_trees(p_node.right, q_node.right, checkR)
elif p_node.right or q_node.right:
# print("F3")
checkR.append(False)
elif p_node or q_node:
# print("F4")
checkR.append(False)
return checkR
print("result", compare_trees(p, q, []))
result = compare_trees(p, q, [])
if False in result:
return False
return True
# return compare_trees(p, q, [])