Same Tree (Leetcode 100)
Technique: FAITH technique of Recursion
Problem Link: https://leetcode.com/problems/same-tree/
class Solution:
def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
if(p is None and q is None):
return True
if(p is not None and q is None):
return False
elif(p is None and q is not None):
return False
else:
l=self.isSameTree(p.left,q.left)
r=self.isSameTree(p.right,q.right)
if(l and r and p.val==q.val):
return True
else:
return False
PreviousConstruct String from a Binary Tree (Leetcode 606)NextCount Nodes Equal to Average of Subtree (Leetcode 2265)
Last updated