test cases incorrect


  • 1
    P

    There are some test cases that are expecting incorrect output values. Namely, one with 6 val->26 nodes connected at the top of the tree (and thus 5 connecting branches) expects 4.


  • 0
    F

    I just noticed this as well. Made me feel better about feeling crazy over this issue.


  • 0
    F

    for those interested,

    This is my code

       int longestUnivaluePath(TreeNode* root) {
        if(root==NULL) return 0; 
        int path = 0;
        helper(root, path, 0);
        return path;
    }
    
    int helper(TreeNode * root, int &path, int curr){
        //bottom of tree up
        if(root==NULL) return 0;
        
        int l = helper(root->left, path,curr);
        int r = helper(root->right, path,curr);
        
        if(root->left){
            if(root->left->val==root->val) l++;
            else l = 0;
        }
        if(root->right){
            if(root->right->val==root->val) r++;
            else r = 0;
        }
        curr = l + r;
        path = max(path,curr);
    
        return curr;
    }

Log in to reply
 

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