image_2021-11-19_01-54-18.png
35.9 KB
#N141. Linked List Cycle
problem link
#solution
problem link
#solution
public class Solution {
public boolean hasCycle(ListNode head) {
if(head==null) return false;
ListNode curr=head, ahead=head;
while(ahead.next!=null&&ahead.next.next!=null){
curr=curr.next;
ahead=ahead.next.next;
if(curr==ahead)
return true;
}
return false;
}
}