class Solution {
public boolean isSymmetric(TreeNode root) {
if (root == null)
return true;
return helper(root.left, root.right);
}
public boolean helper(TreeNode root1, TreeNode root2) {
if (root1 == null && root2 == null)
return true;
if (root1 == null || root2 == null || root1.val != root2.val)
return false;
return helper(root1.left, root2.right) && helper(root1.right, root2.left);
}
}
剑指 Offer 28. 对称的二叉树
最新推荐文章于 2023-02-20 10:29:14 发布