A Simple Easy-understand C++ Solution


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

Log in to reply
 

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