Leetcode in Java && Oracle
420 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2021-11-19_01-54-18.png
35.9 KB
#N141. Linked List Cycle
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;
}
}