python---实现统计一个数字在排序数组中出现的次数。

统计一个数字在排序数组中出现的次数。

------------------------------------------------

此题如此简单,一个for循环就能搞定。。O(n)

# -*- coding:utf-8 -*-
class Solution:
    def GetNumberOfK(self, data, k):
        # write code here
        count = 0
        for i in data:
            if i == k:
                count += 1
        return count

解法是不是很无耻,哈哈

猜你喜欢

转载自blog.csdn.net/qq_40637313/article/details/89044628