100. 相同的树

class Solution:
    def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
        result1 = self.calvals(p)
        result2 = self.calvals(q)
        print(result1,111, result2)
        return result1 == result2
    def calvals(self, root):
        if not root:
            return []
        queue = collections.deque([root])
        result = []
        while queue:
            for i in range(len(queue)):
                node = queue.popleft()
                
                if node:
                    queue.append(node.left)
                    queue.append(node.right)
                    result.append(node.val)
                else:
                    result.append(None)
        return result

你可能感兴趣的:(python,开发语言)