C++ solution, please give me advice


  • 1
    D

    Please give me any advice that I can improve the algo.
    Thanks a lot.

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

Log in to reply
 

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