Linked List Cycle LeetCode solution in Java

1
public class Solution {
2
public boolean hasCycle(ListNode head) {
3
ListNode fast = head;
4
ListNode slow = head;
5
boolean result = false;
6
while (fast != null && fast.next != null) {
7
fast = fast.next.next;
8
slow = slow.next;
9
if (fast == slow) {
10
result = true;
11
break;
12
}
13
}
14
return result;
15
}
16
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0