Skip to content

Commit

Permalink
add same tree
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Jan 10, 2023
1 parent aa2b6df commit 6d99527
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions same-tree/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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:
# Base cases - either both are None (same)
if p is None and q is None:
return True
# One is None, other not (different)
elif p is None or q is None:
return False
return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right) and p.val == q.val

0 comments on commit 6d99527

Please sign in to comment.