Created
June 30, 2015 15:46
-
-
Save lukmdo/70393146f2229ea695ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(items): | |
if not items: | |
return | |
count = 0 | |
best = None | |
for n in items: | |
if count == 0: | |
best = n | |
count += 1 | |
else: | |
if n == best: | |
count += 1 | |
else: | |
count -= 1 | |
if count < 1: | |
return | |
count = 0 | |
for item in items: | |
if item == best: | |
count += 1 | |
if count > len(items) // 2: | |
return best |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment