#include<iostream>
using namespace std;
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution {
public:
TreeNode* mirrorTree(TreeNode* root) {
if(root!=NULL)
{
mirrorTree(root->left);
mirrorTree(root->right);
swap(root->left,root->right);//后序遍历直接交换 秒杀
}
return root;
}
};
int main()
{
}
剑指 Offer 27. 二叉树的镜像
最新推荐文章于 2024-11-06 11:05:01 发布