题目
https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/
解法
class Solution {
/**
* @param ListNode $head
* @return ListNode
*/
function deleteDuplicates($head) {
if (empty($head)) {
return $head;
}
$preValue = null;
/**
* @var ListNode
*/
$preNode = null;
$dummyHead = $head;
while ($dummyHead) {
if ($preValue === $dummyHead->val) {
$preNode->next = $dummyHead->next;
$dummyHead = $dummyHead->next;
} else {
$preNode = $dummyHead;
$dummyHead = $dummyHead->next;
$preValue = $preNode->val;
}
}
return $head;
}
}