What is the leetcode test case?


  • 0
    B

    what does the testcase mean? For example [], does it mean empty pointer?


  • 0

    Yes, that represents the empty tree, and you'll get null/None/nil as input.


  • 0
    B

    Thank you, but in my c code:

    struct TreeNode* invertTree(struct TreeNode* root) 
    {
        struct TreeNode *pTmp = root->left;
        if (root == NULL)
        {
            return NULL;
        }
        invertTree(root->left);
        invertTree(root->right);
        root->left = root->right;
        root->right = pTmp;
        
        return NULL;
    }
    

    fail the test case. It says my input [], my output , expected output []. Runtime is N/A. It seems that the input is not NULL.


  • 0

    The input is null. And then you try to access root->left. Which of course crashes. Do the null test first.


  • 0
    B

    Oh, Thank you, how careless I was. And if I want to pass a tree to the test case [], how to do it? For example, the left is null, the right is null, the val is 0.


  • 0

    That's [0]. See here for more examples/info.


  • 0
    B

    Thank you very much


Log in to reply
 

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