[闲聊] 每日leetcode

楼主: abcd991276 (QQ)   2024-02-26 11:24:07
100.same tree
题目给定两个tree
判断他们是不是长一样
判断节点一样加递回左右子树
class Solution:
def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
if p is not None and q is not None:
return p.val == q.val and self.isSameTree(p.left, q.left) and self.i
sSameTree(p.right, q.right)
elif p is None and q is None:
return True
else:
return False
作者: DJYOSHITAKA (Evans)   2024-02-26 11:31:00
大湿
作者: digua (地瓜)   2024-02-26 11:31:00
大师
作者: wu10200512 (廷廷)   2024-02-26 11:32:00
大师
作者: ijustcame (我才刚来耶)   2024-02-26 11:48:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com