Skip to content

Commit e41e2d7

Browse files
committed
Time: 30 ms (88.28%) | Memory: 16.6 MB (70.01%) - LeetSync
1 parent add2a61 commit e41e2d7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

100-same-tree/same-tree.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
3+
# def __init__(self, val=0, left=None, right=None):
4+
# self.val = val
5+
# self.left = left
6+
# self.right = right
7+
class Solution:
8+
def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
9+
if not p and not q:
10+
return True
11+
if not p or not q:
12+
return False
13+
return p.val == q.val and self.isSameTree(p.left,q.left) and self.isSameTree(p.right,q.right)
14+

0 commit comments

Comments
 (0)