test cases incorrect

  • 3

    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

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

  • 0

    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->val==root->val) l++;
            else l = 0;
            if(root->right->val==root->val) r++;
            else r = 0;
        curr = l + r;
        path = max(path,curr);
        return curr;

  • 0
    This post is deleted!

  • 0

    I hit the same issue. Maybe there is a mistake in the problem description? Or this is a newer test case and was written incorrectly?

  • 0

    Yes! Glad to know I am not the only one hitting the problem.

Log in to reply

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