class Solution {
function searchInsert($nums, $target) {
if (array_search($target, $nums) !== false) {
return array_search($target, $nums);
}
else {
foreach ($nums as $k => $v) {
if ($v > $target) {
return $k;
}
else if (($k+1) == count($nums)) {
return $k+1;
}
}
}
}
}
No comments:
Post a Comment