| Conditions | 4 |
| Paths | 5 |
| Total Lines | 18 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | public static function removeNthFromEnd(?ListNode $head, int $n): ?ListNode |
||
| 12 | { |
||
| 13 | if (!$head) { |
||
| 14 | return null; |
||
| 15 | } |
||
| 16 | $node = new ListNode(); |
||
| 17 | $node->next = $head; |
||
| 18 | $slow = $fast = $node; |
||
| 19 | for ($i = 1; $i <= $n + 1; $i++) { |
||
| 20 | $fast = $fast->next; |
||
| 21 | } |
||
| 22 | while ($fast) { |
||
| 23 | $slow = $slow->next; |
||
| 24 | $fast = $fast->next; |
||
| 25 | } |
||
| 26 | $slow->next = $slow->next->next; |
||
| 27 | |||
| 28 | return $node->next; |
||
| 29 | } |
||
| 52 |