Skip to content

Instantly share code, notes, and snippets.

@lukmdo
Created June 30, 2015 15:46
Show Gist options
  • Save lukmdo/70393146f2229ea695ab to your computer and use it in GitHub Desktop.
Save lukmdo/70393146f2229ea695ab to your computer and use it in GitHub Desktop.
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