forked from Mickey0521/Codility-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDominator.py
More file actions
31 lines (22 loc) · 703 Bytes
/
Dominator.py
File metadata and controls
31 lines (22 loc) · 703 Bytes
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
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
my_dictionary = {}
for item in A:
my_dictionary[item] = 0
for item in A:
my_dictionary[item] += 1
# print(my_dictionary)
have_dominator = False
value_dominator = -1
index_dominator = -1
for index in range( len(A) ):
if my_dictionary[ A[index] ] > float( len(A) / 2):
have_dominator = True
value_dominator = A[index]
index_dominator = index
if have_dominator == False:
return -1
else:
return index_dominator