您的位置:首页 > 编程语言 > Python开发

【leetcode-python】剑指 Offer 53 - I. 在排序数组中查找数字 I

2020-07-15 04:32 459 查看
统计一个数字在排序数组中出现的次数。

示例 1:

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

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

限制:

0 <= 数组长度 <= 50000

参考代码1:
class Solution:
def search(self, nums: List[int], target: int) -> int:
return nums.count(target)
参考代码2:
class Solution:
def search(self, nums: List[int], target: int) -> int:
count = 0
for i in nums:
if i == target:
count += 1
return count
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: