类型:树
-
- 相同的树 💚
https://leetcode-cn.com/problems/same-tree/
❓ 判断两棵树是否相同。
💡 递归
class Solution: def isSameTree(self, p: TreeNode, q: TreeNode) -> bool: if not p and not q: return True elif not p or not q: return False elif p.val != q.val: return False else: return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)时间复杂度:O(min(m, n)),空间复杂度:O(min(m, n))