思路:辅助字典,若存在,则返回字典中相应键对应的值。若不存在,返回0。

Python:

class Solution:
    def search(self, nums: List[int], target: int) -> int:
        from collections import Counter
        help_dict=Counter(nums)
        if target in help_dict:
            return help_dict[target]
        else:
            return 0