Skip to content

Instantly share code, notes, and snippets.

@cangoal
Created June 8, 2015 13:50
Show Gist options
  • Save cangoal/2fc7f680f7a14a66c01a to your computer and use it in GitHub Desktop.
Save cangoal/2fc7f680f7a14a66c01a to your computer and use it in GitHub Desktop.
LeetCode - Linked List Cycle
public boolean hasCycle(ListNode head) {
if(head == null) return false;
ListNode runner = head;
ListNode walker = head;
while(runner.next != null && runner.next.next != null){
runner = runner.next.next;
walker = walker.next;
if(runner == walker){
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment