C++ Easy Solution


  • 0
    J
    class Solution {
    public:
        TreeNode* invertTree(TreeNode* root) {
            if(root==NULL)return root;
            queue<TreeNode*> quu;
            quu.push(root);
            while(!quu.empty()){
                TreeNode* frt=quu.front();quu.pop();
                TreeNode* tmp;
                tmp=frt->right;
                frt->right=frt->left;
                frt->left=tmp;
                if(frt->right!=NULL)quu.push(frt->right);
                if(frt->left!=NULL)quu.push(frt->left);
            }
            return root;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.