Skip to content

Commit 05b8871

Browse files
authored
Majority_element_moore's voting algo
Initial File
1 parent ddace72 commit 05b8871

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Majority_element_moore's

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def majority_ele(A):
2+
curr_majority=A[0]
3+
count=1
4+
size=len(A)
5+
for index in range(1,size):
6+
if curr_majority == A[index]:
7+
count=count+1
8+
else:
9+
count=count-1
10+
if count == 0:
11+
curr_majority = A[index]
12+
count=1
13+
for i in range(size):
14+
if curr_majority == A[i]:
15+
count=count+1
16+
if count>size/2:
17+
return curr_majority

0 commit comments

Comments
 (0)