C++ 5 lines recursive solution


  • 0
    B
    class Solution {
    public:
        TreeNode* invertTree(TreeNode* root) {
            if(!root) return root;
            invertTree(root->left);
            invertTree(root->right);
            swap(root->left,root->right);
            return root;
        }
    };

Log in to reply
 

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