题目:
统计一个数字在排序数组中出现的次数。
leetcode原题
思路:
for循环暴力遍历
代码:
class Solution:
def search(self, nums: List[int], target: int) -> int:
count=0
for i in nums:
if i==target:#目标数字出现时,count加1;反之不做处理
count+=1
return count