Accepted 0ms c++ recursive solution, only 5 lines.


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

Log in to reply
 

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