Day3 在排序数组中查找数字【数组】

题目:
统计一个数字在排序数组中出现的次数。
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

猜你喜欢

转载自blog.csdn.net/weixin_47128888/article/details/112550307
今日推荐