function searchRange($nums, $target) { $res = [-1, -1]; $len = count($nums); for($i=0; $i<$len; $i++){ if($nums[$i] == $target){ $res[0] = $i; break; } } if($res[0] == -1){ return $res; } for($j=$len-1; $j>=0; $j--){ if($nums[$j] == $target){ $res[1] = $j; break; } } return $res; }
leetcode刷题:Find First and Last Position of Element in Sorted Array的PHP解法
最新推荐文章于 2021-01-12 11:28:50 发布