-
Notifications
You must be signed in to change notification settings - Fork 385
Closed
Labels
Description
LeetCode Username
MQuang200
Problem Number, Title, and Link
- 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
Additional context
No response