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

相关推荐

  1. 100. 相同

    2024-01-13 02:48:02       35 阅读
  2. 100. 相同

    2024-01-13 02:48:02       17 阅读
  3. Leetcode 100相同

    2024-01-13 02:48:02       10 阅读

最近更新

  1. android 7.0 tts文字转语音

    2024-01-13 02:48:02       1 阅读
  2. 离线升级docker中的某个镜像——以etcd为例

    2024-01-13 02:48:02       1 阅读
  3. 将pytorch 模型封装为c++ api 例子

    2024-01-13 02:48:02       1 阅读
  4. Rust: 关于Pin以及move前后分析

    2024-01-13 02:48:02       1 阅读
  5. LVS实验

    LVS实验

    2024-01-13 02:48:02      1 阅读

热门阅读

  1. mysql 一对多 合并多个通过 逗号拼接展示

    2024-01-13 02:48:02       37 阅读
  2. python - 依赖 pycryptodome

    2024-01-13 02:48:02       30 阅读
  3. Mysql 触发器

    2024-01-13 02:48:02       38 阅读
  4. Linux中创建文件的基本方法

    2024-01-13 02:48:02       33 阅读
  5. gitlab部署

    2024-01-13 02:48:02       35 阅读
  6. 1. Presto基础

    2024-01-13 02:48:02       33 阅读
  7. 安全基础知识

    2024-01-13 02:48:02       38 阅读
  8. ubuntu设定时间与外部ntp同步

    2024-01-13 02:48:02       41 阅读