力扣刷题
翻转一棵二叉树。
示例:
解题思路:利用解构赋值 将左子树的值改为 继续反转之后的右子树的值 反之也一样
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {TreeNode}
*/
var invertTree = function(root) {
if(!root){return null}
[root.left,root.right]=[invertTree(root.right),invertTree(root.left)]
return root
};