PHP陣列方法
function removeDuplicates(&$nums){
$nums = array_keys(array_count_values($nums));
return count($nums);
}
快慢指標
function removeDuplicates(&$nums)
{
$length = count($nums);
$slowP = 0;
for ($fastP = 0; $fastP < $length; $fastP++) {
if ($nums[$fastP] != $nums[$slowP]) {
$slowP++;
$nums[$slowP] = $nums[$fastP];
}
}
return $slowP + 1;
}