/**
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* };
*/
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param pRoot TreeNode类
* @return TreeNode类
*/
TreeNode* Mirror(TreeNode* pRoot) {
// write code here
//判空
if(pRoot ==NULL)
return nullptr;
//交换左右子树
swap(pRoot->left,pRoot->right);
//递归调用
Mirror(pRoot->left);
Mirror(pRoot->right);
return pRoot;
}
};
标签:right,TreeNode,struct,JZ27,pRoot,return,二叉树,镜像,left
From: https://www.cnblogs.com/H43724334/p/18136975