| Conditions | 6 |
| Paths | 5 |
| Total Lines | 20 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | public static function detectCycle(?ListNode $head): ?ListNode |
||
| 12 | { |
||
| 13 | if (!$head) { |
||
| 14 | return null; |
||
| 15 | } |
||
| 16 | $slow = $fast = $head; |
||
| 17 | while ($fast->next && $fast->next->next) { |
||
| 18 | $slow = $slow->next; |
||
| 19 | $fast = $fast->next->next; |
||
| 20 | if ($slow === $fast) { |
||
| 21 | $curr = $head; |
||
| 22 | while ($curr !== $slow) { |
||
| 23 | $curr = $curr->next; |
||
| 24 | $slow = $slow->next; |
||
| 25 | } |
||
| 26 | return $slow; |
||
| 27 | } |
||
| 28 | } |
||
| 29 | |||
| 30 | return null; |
||
| 31 | } |
||
| 33 |