Solution: C++, 0ms


  • 3
    J
    class Solution {
    public:
        TreeNode* invertTree(TreeNode* root) {
            if (root==NULL || root->left==NULL && root->right==NULL) return root;
            
            TreeNode* temp;
            temp = invertTree(root->left);
            root->left = invertTree(root->right);
            root->right = temp;
    
            return root;
        }
    };

Log in to reply
 

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