题解 | #数组中重复的数字#

数组中重复的数字

https://www.nowcoder.com/practice/6fe361ede7e54db1b84adc81d09d8524

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param numbers int整型一维数组 
# @return int整型
#
class Solution:
    def duplicate(self , numbers: List[int]) -> int:
        # write code here
        from collections import Counter
        #创建 Counter 字典对象
        cout = Counter(numbers)
        for key, val in cout.items():
            if val > 1:
                return(key)
        return -1

全部评论

相关推荐

07-29 14:46
门头沟学院 Java
码农索隆:好了,我说句公道话,咱三都辛苦了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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