(ListNode head)
| 32 | } |
| 33 | |
| 34 | public ListNode isCycleExists(ListNode head){ |
| 35 | ListNode currentHead = head; |
| 36 | |
| 37 | ListNode slowPtr = head; |
| 38 | ListNode fastPtr = head; |
| 39 | |
| 40 | while (fastPtr != null && fastPtr.next != null) { |
| 41 | slowPtr = slowPtr.next; |
| 42 | fastPtr = fastPtr.next.next; |
| 43 | |
| 44 | if (slowPtr == fastPtr) |
| 45 | return slowPtr; |
| 46 | } |
| 47 | |
| 48 | return null; |
| 49 | } |
| 50 | |
| 51 | } |