You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tech-interview-handbook/utilities/python/tree_equal.py

9 lines
268 B

7 years ago
def tree_equal(node1, node2):
if not node1 and not node2:
return True
if not node1 or not node2:
return False
return node1.val == node2.val and \
tree_equal(node1.left, node2.left) and \
tree_equal(node1.right, node2.right)