题目描述 统计一个数字在排序数组中出现的次数。
class Solution {
public int search(int[] nums
, int target
) {
return helper(nums
,target
) - helper(nums
,target
-1);
}
public int helper(int[] nums
,int target
) {
int i
= 0;
int j
= nums
.length
-1;
while(i
<=j
){
int m
= i
+ (j
-i
) /2;
if(nums
[m
] <= target
){
i
= m
+ 1;
}else{
j
= m
- 1;
}
}
return i
;
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-14091.html