image_2022-09-25_15-53-22.png
39.6 KB
#N101. Symmetric Tree
problem link
#solution
problem link
#solution
class Solution {
public boolean isSymmetric(TreeNode root) {
return root==null||func(root.left, root.right);
}
public boolean func(TreeNode left, TreeNode right){
if(left==null && right==null) return true;
if(left==null ^ right==null || left.val!=right.val) return false;
return func(left.left, right.right) && func(left.right, right.left);
}
}⚡2👍1