class Solution(object): def getNumberOfK(self, nums, k): count = 0 for x in nums: if k == x: count += 1 return count
还有更简单的
class Solution(object): def getNumberOfK(self, nums, k): return nums.count(k)
还有更简单的