标签:ref rip OLE class == leetcode equals 转变 数组
判断两颗二叉树是否完全相同,把该树转变为数组展示形式,
前序遍历,然后看结果是否一致即可
class Solution {
String s = "";
void dfs(TreeNode tree){
if (tree == null) return;
s+=tree.val;
if (tree.left!=null) dfs(tree.left);
if (tree.right!=null) dfs(tree.right);
}
public boolean isSameTree(TreeNode p, TreeNode q) {
String a = "";
dfs(p);
a = s;
s = "";
dfs(q);
return a.equals(s);
}
}
标签:ref rip OLE class == leetcode equals 转变 数组
原文地址:https://www.cnblogs.com/acbingo/p/9906169.html