C Solution

  • 0

    In C, I have the following code written:

    struct TreeNode* convertBST(struct TreeNode* root) {
        static int sumToAdd=0;
        if(root != NULL)
    		root->val += sumToAdd;
    		sumToAdd = root->val;
                    return root;
        return root;

    When I am submitting it, I am getting my output is incorrect where as when I run using run command It is correct.
    The test case is: [2,1,3]
    In submit window it is showing my code output as [25,26,23] instead of [5,6,3],
    but by using Run my code also giving correct output [5,6,3]

    is this because of my static variable holding updated value between test case calls?

Log in to reply

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