-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path806.repeated_n_times.py
More file actions
45 lines (38 loc) · 1.01 KB
/
806.repeated_n_times.py
File metadata and controls
45 lines (38 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
# @Time : 2019/2/25 11:46
# @Author : xulzee
# @Email : xulzee@163.com
# @File : 806.repeated_n_times.py
# @Software: PyCharm
class Solution:
def repeatedNTimes1(self, A):
"""
:type A: List[int]
:rtype: int
"""
# Bubble Sort
# for i in range(len(A)):
# for j in range(i, len(A)):
# if A[i] > A[j]:
# A[i] = A[i] ^ A[j]
# A[j] = A[i] ^ A[j]
# A[i] = A[i] ^ A[j]
A = sorted(A)
if A.count(A[len(A)//2]) > A.count(A[len(A)//2 - 1]):
return A[len(A)//2]
else:
return A[len(A)//2-1]
def repeatedNTimes(self, A):
"""
:type A: List[int]
:rtype: int
"""
tmp = set()
for x in A:
if x in tmp:
return x
else:
tmp.add(x)
if __name__ == '__main__':
A = [1, 2, 3, 3]
print(Solution().repeatedNTimes(A))