100. Same Tree

class Solution:
def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
return (self.rec(p,q))

def rec(self,p,q):
if p==None and q==None:
return True
if(p==None or q==None):
return False
if p.val == q.val:
return(self.rec(p.left,q.left) and self.isSameTree(p.right,q.right))

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store