Given a binary tree, check whether it is mirror - symmetric. /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode right) { * this.val = val; * this.left = left; * this.right = right; * } * } */ class Solution { public boolean isSymmetric(TreeNode root) { return check(root,root); } public boolean check(TreeNode p,TreeNode q){ if(p == null && q == null){ return true; } if(p == null || q == null){ return false; } return p.val == q.val && check(p.left,q.right) && check(p.right,q.left); }} // Remarks are mainly traversal and comparison of the left and right subtrees. The traversal here is to pass in the root of the same tree, alias P and q point to the left and right subtrees respectively, and then traversal again. Then there are four sub-tree node comparison conditions, as shown in the codeCopy the code