| 11 | |
| 12 | |
| 13 | class Solution { |
| 14 | public static boolean detectLoop(Node head){ |
| 15 | // Add code here |
| 16 | //basic metehod we use here is we take two node fast and slow fast node will movw twice fast as slow |
| 17 | //during traversal of list we check that is value of slow and fast node are equal it means there is a loop. |
| 18 | //otherwise it is not possible |
| 19 | Node slow=head,fast=head; |
| 20 | boolean f=false; |
| 21 | while(fast!=null && fast.next!=null){ |
| 22 | slow=slow.next; |
| 23 | fast=fast.next.next; |
| 24 | if(slow==fast){ |
| 25 | f=true; |
| 26 | break; |
| 27 | } |
| 28 | |
| 29 | } |
| 30 | return f; |
| 31 | } |
| 32 | } |
nothing calls this directly
no outgoing calls
no test coverage detected