Shared my c++ recursive solution(0 ms)


  • 0
    A
    class Solution {
    public:
        TreeNode* invertTree(TreeNode* root) {
        	if(root == NULL)
        		return NULL;
            
            invertTree(root->left);
            TreeNode* left = root->left;
            TreeNode* right = root->right;
            root->left = right;
    		root->right = left;        
            invertTree(right);
    
            return root;
        }
    };

Log in to reply
 

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