题目链接
思路
将左右子树抽象为两个结点,直接进行交换。然后再递归左右子树。
代码
class Solution {
public TreeNode invertTree(TreeNode root) {
if(root == null){
return null;
}
TreeNode temp = root.left;
root.left = root.right;
root.right = temp;
root.left = invertTree(root.left);
root.right = invertTree(root.right);
return root;
}
}
标签:right,TreeNode,invertTree,二叉树,226,root,LeetCode,left
From: https://www.cnblogs.com/shixuanliu/p/17062012.html