牛客网上的剑指 offer的在线编程:
题目描述
统计一个数字在排序数组中出现的次数。
# -*- coding:utf-8 -*-
'''
数字在排序数组中出现的次数
题目描述
统计一个数字在排序数组中出现的次数。
'''
class Solution:
# 方法一:
def GetNumberOfK1(self, data, k):
# write code here
if len(data) == 0:
return 0
else:
return data.count(k)
# 方法二:
def GetNumberOfK(self, data, k):
# write code here
if len(data) == 0: