题目:
题解:
class Solution:def isSameTree(self, p: TreeNode, q: TreeNode) -> bool:if not p and not q:return Trueif not p or not q:return Falsequeue1 = collections.deque([p])queue2 = collections.deque([q])while queue1 and queue2:node1 = queue1.popleft()node2 = queue2.popleft()if node1.val != node2.val:return Falseleft1, right1 = node1.left, node1.rightleft2, right2 = node2.left, node2.rightif (not left1) ^ (not left2):return Falseif (not right1) ^ (not right2):return Falseif left1:queue1.append(left1)if right1:queue1.append(right1)if left2:queue2.append(left2)if right2:queue2.append(right2)return not queue1 and not queue2