Sobes.tech
Junior — Senior

Comparison of the structure and values of two binary trees

livecode

Task condition

It is necessary to implement a function that:

  • takes two root nodes of type TreeNode, representing two binary trees;
  • determines whether both trees are identical in shape and node values;
  • returns True if the trees are completely identical, and False otherwise.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None