6 line C++ 0ms recursive solution


  • 1
    O
    class Solution {
    public:
        TreeNode* invertTree(TreeNode* root) {
            if (root == NULL) return root;
            auto l = invertTree(root->right);
            auto r = invertTree(root->left);
            root->left = l;
            root->right = r;
            return root;
        }
    };

Log in to reply
 

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