Skip to content

Missing Test Case - 1367. Linked List in Binary Tree #23959

@MQuang200

Description

@MQuang200

LeetCode Username

MQuang200

Problem Number, Title, and Link

  1. Linked List in Binary Tree https://leetcode.com/problems/linked-list-in-binary-tree/

Bug Category

Missing test case (Incorrect/Inefficient Code getting accepted because of missing test cases)

Bug Description

For the test case with ListNode = [3,2] and TreeNode = [1,3,null,null,3,null,1,null,2]. The right output is false, but the current accepted solution's output is true

Language Used for Code

Java

Code used for Submit/Run operation

class Solution {
    public boolean isSubPath(ListNode head, TreeNode root) {
        return dfs(head, head, root);        
    }

    private boolean dfs(ListNode head, ListNode cur, TreeNode root) {
        if (cur == null) {
            return true;
        }

        if (root == null) {
            return false;
        }

        if (root.val == cur.val) {
            cur = cur.next;
        } else if (root.val == head.val) {
            head = head.next;
        } else {
            cur = head;
        }

        return dfs(head, cur, root.left) || dfs(head, cur, root.right);
    }
}

Expected behavior

The output should be false instead of right for an accepted solution

Screenshots

Screenshot 2024-09-07 at 11 53 17

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions