统计一个数字在排序数组中出现的次数。
1 # -*- coding:utf-8 -*- 2 class Solution: 3 def GetNumberOfK(self, data, k): 4 n = len(data) 5 if n == 0: 6 return 0 7 cnt = 0 8 find = False 9 for i in range(n): 10 if data[i] == k: 11 cnt += 1 12 if not find: 13 find = True 14 else: 15 if find: 16 break 17 return cnt 18 # write code here