leetcode
leetcode copied to clipboard
Bug Report for linked-list-cycle-detection
Bug Report for https://neetcode.io/problems/linked-list-cycle-detection
Title: Java submission initially fails with compilation errors but is accepted after multiple resubmissions
Description
When submitting a Java solution, the first few submissions consistently fail with a compilation error. However, resubmitting the exact same code multiple times (without making any changes) eventually results in the solution being accepted.
Steps to Reproduce
- Open the Linked List Cycle problem.
- Select Java as the language.
- Paste a valid Java solution.
- Click Submit.
- Observe that the submission fails with a compilation error.
- Without modifying the code, click Submit again several times.
Expected Result
The solution should compile and be evaluated successfully on the first submission.
Actual Result
The initial submission(s) fail with a compilation error. After multiple resubmissions of the exact same code, the solution is accepted without any code changes.
Notes
- The code is unchanged between submissions.
- The issue appears to be intermittent and related to the submission/judging process rather than the solution itself.
- This may indicate a problem with the Java compilation or judging infrastructure.
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public boolean hasCycle(ListNode head) {
ListNode fast = head, slow = head;
while (fast != null && fast.next != null) {
fast = fast.next.next;
slow = slow.next;
if (fast == slow) {
return true;
}
}
return false;
}
}