Last active
March 13, 2023 00:40
-
-
Save Khamies/2915adcecd9d6e74de448c07b6469f80 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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