1. /**
    2. * Definition for a binary tree node.
    3. * function TreeNode(val, left, right) {
    4. * this.val = (val===undefined ? 0 : val)
    5. * this.left = (left===undefined ? null : left)
    6. * this.right = (right===undefined ? null : right)
    7. * }
    8. */
    9. /**
    10. * @param {TreeNode} root
    11. * @return {boolean}
    12. */
    13. var isSymmetric = function(root) {
    14. let stack = [root];
    15. while (stack.length) {
    16. let temp = [];
    17. for (let item of stack) {
    18. if (item) {
    19. temp.push(item.left);
    20. temp.push(item.right);
    21. }
    22. }
    23. if (stack.length > 1) {
    24. let start = 0, end = stack.length - 1;
    25. while (start < end) {
    26. if (stack[start]?.val !== stack[end]?.val) {
    27. return false;
    28. }
    29. ++start;
    30. --end;
    31. }
    32. }
    33. stack = temp;
    34. }
    35. return true;
    36. };