剑指 Offer 27 二叉树的镜像
概述
https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof/
https://leetcode.com/problems/invert-binary-tree/
递归法
class Solution {
public:
TreeNode* mirrorTree(TreeNode* root) {
if (!root) return nullptr;
auto temp = root->left;
root->left = mirrorTree(root->right);
root->right = mirrorTree(temp);
return root;
}
};
Links: sword-offer-27