Short "0ms" C++ solution with recursion


  • 0
    D
    class Solution {
    public:
        TreeNode* invertTree(TreeNode* root) {
            if (root) {
                root->left = invertTree(root->left), root->right = invertTree(root->right);
                std::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.