Skip to content

Instantly share code, notes, and snippets.

@Khamies
Last active March 13, 2023 00:40
Show Gist options
  • Select an option

  • Save Khamies/2915adcecd9d6e74de448c07b6469f80 to your computer and use it in GitHub Desktop.

Select an option

Save Khamies/2915adcecd9d6e74de448c07b6469f80 to your computer and use it in GitHub Desktop.
def is_same_BT(root1, root2):
def check(root1, root2):
if not root1 and not root2: # check for the end of both trees.
return True
if not root1 or not root2: # Check for the heights' similarity.
return False
if root1.val != root2.val: # check for the key values' similarity.
return False
return check(root1.left, root2.left) and check(root1.right, root2.right)
return check(root1, root2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment