Skip to content

Instantly share code, notes, and snippets.

@braddotcoffee
Last active November 11, 2023 05:19
Show Gist options
  • Select an option

  • Save braddotcoffee/9afcef006cbc502544c3a0f02b3d3e19 to your computer and use it in GitHub Desktop.

Select an option

Save braddotcoffee/9afcef006cbc502544c3a0f02b3d3e19 to your computer and use it in GitHub Desktop.
100. Same Tree
# 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