/** * Definition for a binary tree node. * function TreeNode(val, left, right) { * this.val = (val===undefined ? 0 : val) * this.left = (left===undefined ? null : left) * this.right = (right===undefined ? null : right) * } *//** * @param {TreeNode} root * @return {boolean}*/var isSymmetric = function(root) { let stack = [root]; while (stack.length) { let temp = []; for (let item of stack) { if (item) { temp.push(item.left); temp.push(item.right); } } if (stack.length > 1) { let start = 0, end = stack.length - 1; while (start < end) { if (stack[start]?.val !== stack[end]?.val) { return false; } ++start; --end; } } stack = temp; } return true;};