about points problem


  • 0
    S

    In the definition of function DLR, I use DLR(TreeNode* root, TreeNode*& this_res) for accepted. However, when I remove the &, becoming DLR(TreeNode* root, TreeNode*& this_res), will be wrong answer. Can anyone solve this problem for me? Thank you.
    ...
    class Solution {
    public:
    void DLR(TreeNode* root, TreeNode*& this_res)
    {
    if(root==NULL) return;
    TreeNode* mid=(TreeNode*)malloc(sizeof(TreeNode));
    mid->val=root->val;
    mid->left=NULL;
    mid->right=NULL;
    this_res->right=mid;
    this_res=mid;
    DLR(root->left, this_res);
    DLR(root->right, this_res);
    }
    void flatten(TreeNode*& root) {
    TreeNode* res=(TreeNode*)malloc(sizeof(TreeNode));
    TreeNode* this_res=res;
    DLR(root, this_res);
    root=res->right;
    }
    };
    ...


Log in to reply
 

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