class Solution {
public int[] searchRange(int[] nums, int target) {
int left = 0,right =nums.length-1;
while(left <= right){
if(nums[left] != target){
left +=1;
}else{
if(nums[right] != target){
right -=1;
}else{
return new int[]{left,right};
}
}
}
return new int[]{-1,-1};
}
}
简单的双指针方法求前后相同值的坐标问题
最新推荐文章于 2024-07-14 11:23:58 发布