| 25 | // } |
| 26 | |
| 27 | public boolean isSymmetric(TreeNode root) { |
| 28 | if (root == null) return true; |
| 29 | LinkedList<TreeNode> q = new LinkedList<>(); |
| 30 | q.add(root.left); |
| 31 | q.add(root.right); |
| 32 | TreeNode left, right; |
| 33 | while (q.size() > 1) { |
| 34 | left = q.pop(); |
| 35 | right = q.pop(); |
| 36 | if (left == null && right == null) continue; |
| 37 | if (left == null || right == null) return false; |
| 38 | if (left.val != right.val) return false; |
| 39 | q.add(left.left); |
| 40 | q.add(right.right); |
| 41 | q.add(left.right); |
| 42 | q.add(right.left); |
| 43 | } |
| 44 | return true; |
| 45 | } |
| 46 | |
| 47 | public static void main(String[] args) { |
| 48 | Solution solution = new Solution(); |