fork download
  1. /**
  2.  * Definition for singly-linked list.
  3.  * class ListNode {
  4.  * int val;
  5.  * ListNode next;
  6.  * ListNode(int x) {
  7.  * val = x;
  8.  * next = null;
  9.  * }
  10.  * }
  11.  */
  12. public class Solution {
  13. public boolean hasCycle(ListNode head) {
  14.  
  15.  
  16. ListNode slow = head;
  17. ListNode fast = head;
  18.  
  19. while (fast != null && fast.next != null) {
  20.  
  21.  
  22. slow = slow.next;
  23. fast = fast.next.next;
  24.  
  25.  
  26. if (slow == fast)
  27. return true;
  28. }
  29.  
  30. return false;
  31. }
  32. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:12: error: class Solution is public, should be declared in a file named Solution.java
public class Solution {
       ^
Main.java:13: error: cannot find symbol
    public boolean hasCycle(ListNode head) {
                            ^
  symbol:   class ListNode
  location: class Solution
Main.java:16: error: cannot find symbol
        ListNode slow = head;
        ^
  symbol:   class ListNode
  location: class Solution
Main.java:17: error: cannot find symbol
        ListNode fast = head;
        ^
  symbol:   class ListNode
  location: class Solution
4 errors
stdout
Standard output is empty