My solution(C++) 3ms


  • 0
    X
    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.