class Solution { public: TreeNode *invertTree(TreeNode *root) { if (root == NULL) return NULL; queue<TreeNode *> q; q.push(root); while (!q.empty()) { auto now = q.front(); q.pop(); if (now->left != NULL) q.push(now->left); if (now->right != NULL) q.push(now->right); swap(now->left,now->right); } return root; } }; class Solution { public: TreeNode* invertTree(TreeNode* root) { if(root==NULL) return NULL; invertTree(root->left); invertTree(root->right); swap(root->left,root->right); return root; } };