翻转二叉树:
/**
* 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 {TreeNode}
*/
// 递归法
let invertTree = function(root) {
if(root === null) return null;
// 交换左右子树
[root.left,root.right] = [root.right,root.left];
// 左子树递归
invertTree(root.left);
// 右子树递归
invertTree(root.right);
return root;
};