LeetCode打卡52

统计一个数字在排序数组中出现的次数。

示例 1:

输入: nums = [5,7,7,8,8,10], target = 8
输出: 2
示例 2:

输入: nums = [5,7,7,8,8,10], target = 6
输出: 0

代码:

int search(int* nums, int numsSize, int target){
int i,j=0;
for(i=0;i<numsSize;i++)
{
    if(nums[i]==target)
     j++;
}
return j;
}

猜你喜欢

转载自blog.csdn.net/m0_48423612/article/details/107869600