import java.util.*;
public class Solution {
public boolean isSameTree (TreeNode root1, TreeNode root2) {
// 预处理
if (root1 == null && root2 == null) return true;
if (root1 == null || root2 == null) return false;
// 判断根节点是否相同
if (root1.val != root2.val) {
return false;
} else {
// 递归比较其左右子树
return isSameTree(root1.left,root2.left) && isSameTree(root1.right,root2.right);
}
}
}



京公网安备 11010502036488号