Last active
November 11, 2023 05:19
-
-
Save braddotcoffee/9afcef006cbc502544c3a0f02b3d3e19 to your computer and use it in GitHub Desktop.
100. Same Tree
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
| # Definition for a binary tree node. | |
| # class TreeNode: | |
| # def __init__(self, val=0, left=None, right=None): | |
| # self.val = val | |
| # self.left = left | |
| # self.right = right | |
| class Solution: | |
| def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool: | |
| if p is None or q is None: | |
| return p == q | |
| if p.val != q.val: | |
| return False | |
| return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment