/*
* @lc app=leetcode.cn id=226 lang=javascript
*
* [226] 翻转二叉树
*/
// @lc code=start
/**
* 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}
*/
var invertTree = function(root) {
if(!root) return null;
//获取左右根节点
const left=invertTree(root.left);
const right=invertTree(root.right);
//翻转
root.left=right;
root.right=left;
return root;
};
// @lc code=end