标签:每日 ini code style 思路 and width class com
递归
思路:
递归判断根节点,左子树,右子树是否相同。
代码:
# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def isSameTree(self, p: TreeNode, q: TreeNode) -> bool: if not p and not q: return True if not q or not p: return False if p.val != q.val: return False return self.isSameTree(p.right, q.right) and self.isSameTree(p.left, q.left)
标签:每日 ini code style 思路 and width class com
原文地址:https://www.cnblogs.com/nilhxzcode/p/13186761.html