100. The same tree

# Definition A for binary Tree Node. 
# Class the TreeNode: 
#      DEF the __init __ (Self, X): 
#          self.val = X 
#          self.left = None 
#          self.right = None 

class Solution:
     DEF isSameTree (Self, P: the TreeNode , q: TreeNode) -> BOOL:
         # If two trees do not exist, returns True 
        IF the p- IS None and q IS None:
             return True 
        
        # If there are two trees 
        IF the p- IS  not None and q IS not None:
             return p.val == q.val and self.isSameTree (p.left, q.left) and self.isSameTree (p.right, q.right) 
        
        # a tree there is a tree there is no 
        return False

 

Guess you like

Origin www.cnblogs.com/WJZheng/p/11425847.html
Recommended