<span>leetcode-961 N-Repeated Element in Size 2N Array</span>
题目:
In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeated N times. Return the element repeated N times.
实例输出:
Input: [1,2,3,3] Output: 3
Input: [2,1,2,5,3,2]
Output: 2
本题就是一个简单的字典统计,然后找到出现了n次的数字输出就行了。
1 class Solution: 2 def repeatedNTimes(self, A: List[int]) -> int: 3 dic = {} 4 for i in A: 5 if i in dic: 6 dic[i] += 1 7 else: 8 dic[i] = 1 9 for i in dic: 10 if dic[i] * 2 == len(A): 11 return i