/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } *///这是我自己的解法classSolution{publicbooleanisSymmetric(TreeNoderoot){if(root==null)returntrue;//层序遍历 存储到List中//然后双指针校验回文数LinkedList<TreeNode>queue=newLinkedList<>();queue.offer(root);while(!queue.isEmpty()){intsize=queue.size();ArrayList<TreeNode>list=newArrayList<>();for(inti=0;i<size;i++){TreeNodenode=queue.poll();list.add(node);if(node!=null){queue.offer(node.left);queue.offer(node.right);}}//遍历数组inti=0,j=list.size()-1;while(i<j){TreeNodenode1=list.get(i);TreeNodenode2=list.get(j);if(node1!=null&&node2!=null){if(node1.val!=node2.val){returnfalse;}}elseif(node1!=null||node2!=null){returnfalse;}i++;j--;}}returntrue;}}