import java.util.Objects;class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; }}class Solution { private boolean isSame(TreeNode left, TreeNode right) { if (Objects.isNull(left) && Objects.isNull(right)) { return true; } if (Objects.isNull(left) || Objects.isNull(right)) { return false; } if (left.val != right.val) { return false; } return isSame(left.left, right.right) && isSame(left.right, right.left); } public boolean isSymmetric(TreeNode root) { if (Objects.isNull(root)) { return true; } return isSame(root.left, root.right); }}