【Leetcode】Same Tree
摘要:
给定两棵二叉树,判断是否相等(即树的结构以及各结点中的值都一样)Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.思路:可以分别把树先序和中序遍历到两个数组,然后比较遍历序列,但空间复杂度比较大。更直接的方法是使用递归判断,即先判断根结点是否相等,然后判断左右子树是否分别相等,代码如下 阅读全文
浙公网安备 33010602011771号