题解 | #数组中只出现一次的数(其它数出现k次)#

数组中只出现一次的数(其它数出现k次)

https://www.nowcoder.com/practice/5d3d74c3bf7f4e368e03096bb8857871

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param arr int整型一维数组 
# @param k int整型 
# @return int整型
#
class Solution:
    def foundOnceNumber(self , arr: List[int], k: int) -> int:
        # write code here
        a = dict()
        for i in arr:
            if i not in a:
                a[i] = 1
            else:
                a[i] += 1
                if a[i] == k:
                    del a[i]
        for i in a.keys():
            return i
        
        

全部评论

相关推荐

昨天 11:42
江西农业大学 C++
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 12:10
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务