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.
 



Example 1:
Input: [1,2,3,3]
Output: 3


Example 2:
Input: [2,1,2,5,3,2]
Output: 2


Example 3:
Input: [5,1,5,2,5,3,5,4]
Output: 5

 
Note:

4 <= A.length <= 10000
0 <= A[i] < 10000
A.length is even

Source: leetcode | Difficulty: EASY
Tags: Data structures

Starter code: class Solution:
    def repeatedNTimes(self, A: List[int]) -> int:
        

Solutions:
class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		dict_ = dict()
		for a in A:
			if a in dict_:
				return a
			else:
				dict_[a] = 1


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		for i in range(1, len(A)):
			if A[i] == A[i - 1] or (i - 2 >= 0 and A[i] == A[i - 2]):
				return A[i]
		return A[0]


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		from collections import Counter
		c = Counter(A)
		c = list(c.most_common(1))
		return c[0][0]


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		N = len(A)
		counter = {}
		for num in A:
			if num in counter:
				counter[num] += 1
			else:
				counter[num] = 1
			if counter[num] == N // 2:
				return num


from collections import Counter as di

class Solution:

	def repeatedNTimes(self, a: List[int]) -> int:
		d = di(a)
		maxi = len(a) // 2
		return d.most_common(1)[0][0]
		for i in d:
			if d[i] == maxi:
				return i


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		rep = len(A) // 2
		d = {}
		for i in A:
			if i in d:
				d[i] += 1
			if i not in d:
				d[i] = 1
			if d[i] == rep:
				return i


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		nums = {}
		for i in A:
			if i not in list(nums.keys()):
				nums[i] = 1
			else:
				nums[i] += 1
		print(nums)
		for i in nums:
			if nums[i] == len(A) / 2:
				return i


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		N = len(A)
		freq = {}
		maxv = (None, -math.inf)
		for v in A:
			if v not in freq:
				freq[v] = 0
			freq[v] += 1
			if freq[v] > maxv[1]:
				maxv = (v, freq[v])
			if freq[v] == N:
				return v
		return maxv[0]


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		N = len(A) // 2
		return (sum(A) - sum(set(A))) // (N - 1)


from collections import Counter

class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		ans = 0
		c = Counter(A)
		count = 0
		for i in c:
			print('{} = {}'.format(i, c[i]))
			if c[i] > count:
				count = c[i]
				ans = i
		return ans


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		d = {}
		for i in A:
			if i in d:
				return i
			else:
				d[i] = 1


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		for i in range(len(A)):
			for j in A[:i]:
				if j == A[i]:
					return j


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		dic = collections.Counter(A)
		for num in dic:
			if dic[num] > 1:
				return num


from collections import Counter as C

class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		s = C(A).most_common()
		return s[0][0]


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		dic = {}
		for element in A:
			if not element in dic:
				dic[element] = 1
			else:
				return element


class Solution:

	def repeatedNTimes(self, qq: List[int]) -> int:
		stack = []
		for i in qq:
			if i not in stack:
				stack.append(i)
			else:
				return i


from collections import Counter

class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		cnt = Counter(A).most_common(1)
		return cnt[0][0]


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		count = collections.Counter(A)
		for i in count:
			if count[i] > 1:
				return i


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		size = len(A)
		n = size / 2
		appear = {}
		for i in range(size):
			if A[i] not in list(appear.keys()):
				appear[A[i]] = 1
			else:
				appear[A[i]] += 1
		for i in list(appear.items()):
			if i[1] == n:
				return i[0]


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		tracker = set()
		for num in A:
			if not num in tracker:
				tracker.add(num)
			else:
				return num


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		counter = collections.Counter(A)
		mostc = counter.most_common(1)
		for (key, value) in mostc:
			return key


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		if A == []:
			return 0
		d = {}
		for i in A:
			if i not in d.keys():
				d[i] = 1
			else:
				return i
		return 0


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		maos = {x: 0 for x in set(A)}
		for x in A:
			maos[x] += 1
		for x in maos:
			if maos[x] == len(A) // 2:
				return x


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		check = set()
		for num in A:
			if num in check:
				return num
			check.add(num)


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		sA = sorted(A)
		temp = None
		for i in sA:
			if i == temp:
				return i
			temp = i


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		temp = None
		for i in A:
			if i == temp:
				return i
			temp = i
		if A[0] == A[-2] or A[0] == A[-1]:
			return A[0]
		elif A[-1] == A[-3]:
			return A[-1]


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		record = set()
		for a in A:
			if a in record:
				return a
			else:
				record.add(a)


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		ans = Counter(A)
		return sorted(list(ans.keys()), key=lambda x: ans.get(x), reverse=True)[0]


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		d = {}
		for value in A:
			if value in d:
				return value
			d[value] = 1


class Solution:

	def repeatedNTimes(self, A) -> int:
		B = list(A)
		B.sort()
		for i in range(0, len(B)):
			if B[i] == B[i + 1]:
				return B[i]
			else:
				pass
p = Solution()
testList = [5, 1, 5, 2, 5, 3, 5, 4]
print(p.repeatedNTimes(testList))


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		for (i, a) in enumerate(A):
			if a in A[:i]:
				return a


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		myDict = collections.Counter(A)
		for _ in myDict:
			if myDict[_] > 1:
				return _


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		n = len(A)
		if n == 0:
			return []
		if n == 2:
			return A[0]
		A.sort()
		for i in range(n):
			if A[i] == A[i + 1]:
				return A[i]


from collections import Counter

class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		stack = []
		for n in A:
			if n not in stack:
				stack.append(n)
			else:
				return n


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		B = A.copy()
		for x in A:
			B.remove(x)
			if x in B:
				return x


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		rep = {}
		for item in A:
			if item not in rep:
				rep[item] = 1
			else:
				return item
		return None


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		N = len(A) / 2
		for num in A:
			if A.count(num) == N:
				return num


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		for i in range(0, len(A)):
			new = [A[i]]
			for j in range(i + 1, len(A)):
				if A[i] == A[j]:
					new.append(A[i])
					if len(new) == len(A) / 2:
						print(new)
						return A[i]


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		myDict = {}
		for i in A:
			myDict[i] = myDict.get(i, 0) + 1
			if myDict[i] == len(A) / 2:
				return i


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		dic = {}
		for i in A:
			if i not in dic:
				dic[i] = 0
			else:
				return i


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		count_dict = collections.Counter(A)
		for (key, value) in list(count_dict.items()):
			if value > 1:
				return key


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		result = A[0]
		count = 0
		if A.count(result) == len(A) // 2:
			return result
		for i in A[1:]:
			if count == 0:
				result = i
				print('a')
				count = 1
			elif result == i:
				print('b')
				count += 1
			else:
				print('c')
				count -= 1
		return result


from collections import Counter

class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		n = len(A) // 2
		d = Counter(A)
		for (idx, val) in d.items():
			if val == n:
				return idx
		return -1


import collections

class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		dic = Counter(A)
		for i in dic:
			if dic[i] > 1:
				return i


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		occurences = set()
		for val in A:
			if val in occurences:
				return val
			occurences.add(val)


class Solution(object):

	def repeatedNTimes(self, A):
		for k in range(1, 4):
			for i in range(len(A) - k):
				if A[i] == A[i + k]:
					return A[i]


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		length = len(A)
		n = length // 2
		mydict = {}
		for item in A:
			mydict[item] = mydict.get(item, 0) + 1
			if mydict[item] == n:
				return item


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		from collections import Counter
		cc = Counter(A)
		for key in list(cc.keys()):
			if cc[key] == len(A) // 2:
				return key


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		j = set()
		for num in A:
			if num in j:
				return num
			else:
				j.add(num)
		return False


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		a = sum(A)
		b = sum(set(A))
		n = len(A) // 2
		if a == 0:
			return 0
		c = (a - b) // (n - 1)
		return c


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		c = collections.Counter(A)
		for k in c:
			if c[k] == len(A) // 2:
				break
		return k


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		N = len(A) // 2
		A_map = defaultdict(int)
		for a in A:
			A_map[a] += 1
			if A_map[a] == N:
				return a


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		twoN = len(A)
		N = twoN // 2
		unique = N + 1
		hashMap = {}
		for num in A:
			if num not in hashMap:
				hashMap[num] = 1
			else:
				hashMap[num] += 1
		for (key, value) in hashMap.items():
			if value == N:
				return key


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		count = collections.Counter(A)
		repeat = len(A) // 2
		for key in count:
			if count[key] == repeat:
				return key
		return -1


class Solution:

	def repeatedNTimes(self, A: List[int]) -> int:
		dic = self.convert_to_dic(A)
		for i in dic:
			if dic[i] > 1:
				return i

	def convert_to_dic(self, A):
		dic = {}
		for i in A:
			if i in dic:
				dic[i] += 1
			else:
				dic[i] = 1
		return dic