Skip to content

Instantly share code, notes, and snippets.

@Siyu-Lei
Created May 29, 2018 00:22
Show Gist options
  • Save Siyu-Lei/4ae868c9c5bd08c67e8e160a646825d6 to your computer and use it in GitHub Desktop.
Save Siyu-Lei/4ae868c9c5bd08c67e8e160a646825d6 to your computer and use it in GitHub Desktop.
public class Solution {
public boolean hasCycle(ListNode head) {
ListNode slow = head;
ListNode fast = head;
while (fast != null && fast.next != null) {
slow = slow.next;
fast = fast.next.next;
if (slow == fast) {
return true;
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment