___Cyber___
Senior Member
PHP:
class Solution {
/**
* @param ListNode $node
* @return
*/
function deleteNode($node) {
$cur = $node;
// replace node value with the next, stopping at the second-last position
while ($cur->next->next) {
$cur->val = $cur->next->val;
$cur = $cur->next;
}
// swap the second-last node with the last and remove it.
$cur->val = $cur->next->val;
$cur->next = null;
}
}