| Conditions | 5 |
| Paths | 7 |
| Total Lines | 19 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 31 | public static function removeNthFromEnd2(?ListNode $head, int $n): ?ListNode |
||
| 32 | { |
||
| 33 | if (!$head) { |
||
| 34 | return null; |
||
| 35 | } |
||
| 36 | $slow = $fast = $head; |
||
| 37 | for ($i = 0; $i < $n; $i++) { |
||
| 38 | $fast = $fast->next; |
||
| 39 | } |
||
| 40 | if (!$fast) { |
||
| 41 | return $head->next; |
||
| 42 | } |
||
| 43 | while ($fast->next) { |
||
| 44 | $slow = $slow->next; |
||
| 45 | $fast = $fast->next; |
||
| 46 | } |
||
| 47 | $slow->next = $slow->next->next; |
||
| 48 | |||
| 49 | return $head; |
||
| 50 | } |
||
| 52 |