Is C++ test case having a bug?


  • 1
    B

    This test case is having duplicate values of -100, which happens to be in the input as well.
    This TC seems to be in C++ TC list only. My equivalent Java code passed with no failures. Anyone else is having this issue?

    [37,-34,-48,null,-100,-100,48,null,null,null,null,-54,null,-71,-22,null,null,null,8]
    node with value -100
    node with value -71


  • 0
    A

    I got same issue in JAVA test case. This should be a bug. Don't worry. They may fix this soon.


  • 1

    @bury I am not quite sure how do you get that idea? Can you just paste your code first? Here is my current test with this code in C++, which just ACed with ease.

    class Solution {
    public:
        TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) 
        {
            if(!q) return p;
            if(!p) return q;
            if(!root || root==p || root==q) return root;
            TreeNode *l = lowestCommonAncestor(root->left, p, q);
            TreeNode *r = lowestCommonAncestor(root->right, p, q);
            if(l&&r) return root;
            if(!l) return r;
            if(!r) return l;
            return NULL;
        }
    };
    

  • 0
    B
    This post is deleted!

  • 0
    B

    @LHearen @AdonisSaveWorld Thanks both for responding!
    I found the problem....in @LHearen 's code, it compares the pointer values, while my code compares the node value by using "root->val == p->val"..
    It eventually comes back to the requirement...

    Since a binary tree doesn't mean unique value (not BST tree). I accept that the test case is correct :)


Log in to reply
 

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