琢磨了半天,一看题解,我人傻了
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
void mirror(TreeNode* root) {
if (!root) return;
swap(root->left, root->right); //这里交换的是指针,不是结构体
mirror(root->left);
mirror(root->right);
}
};