这是problem
- 创建新树 node
- 分配根->;向左->;正当
- 分配根->;权利->;左边
解决方案是
function invertTree(root) {
const queue = [root];
while (queue.length) {
const n = queue.pop();
if (n != null) {
[n.left, n.right] = [n.right, n.left];
queue.push(n.left, n.right);
}
}
return root;
};
然而,我感到困惑的是,将队列更改为root.