/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { public boolean isSymmetric(TreeNode root) { if (root == null) return true; return check(root, root); } private boolean check(TreeNode left, TreeNode right) { if (left == null && right == null) return true; if (left == null || right == null) return false; return (left.val == right.val) && check(left.right, right.left) && check(right.left, left.right); }}