function missingNumber($nums) {
sort($nums);
foreach ($nums as $key => $num) {
if ($key != $num) {
return $key;
}
}
return count($nums);
}
echo missingNumber([0, 3, 1]); // 2
echo missingNumber([0, 1]); // 2