<?phpClass ListNode { public $val = 0; public $next; public function __construct($val) { $this->val = $val; } public function __get($name) { return null; }}class Solution { public function removeNthFromEnd(ListNode $head, $n) { $dummy = new ListNode(0); $dummy->next = $head; $fastP = $dummy; $slowP = $dummy; for ($i = 0; $i <= $n; $i++) { $fastP = $fastP->next; } while ($fastP->next) { $fastP = $fastP->next; $slowP = $slowP->next; } $slowP->next->next = $fastP; return $dummy->next; }}$head = new ListNode(1);$head->next = new ListNode(2);$head->next->next = new ListNode(3);$head->next->next->next = new ListNode(4);$head->next->next->next->next = new ListNode(5);$cls = new Solution();$ret = $cls->removeNthFromEnd($head, 2);print_r($ret);