Skip to content
On this page

Invert Binary Tree

leetcode 226. Invert Binary Tree

cpp
TreeNode* invertTree(TreeNode* root) {
    invert(root);
    return root;
}

void invert(TreeNode* root) {
    if(root){
        swap(root->left, root->right);
        invert(root->left);
        invert(root->right);            
    }
}

Released under the MIT License.