Last active
August 29, 2015 14:23
-
-
Save lukmdo/479a87e40c17d2e0e21b 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
""" | |
FIND MOST COMMON ELEMENT IN LIST | |
- what is "most common" | |
- restrictions | |
- list properties | |
- tests? | |
""" | |
def solution(items): | |
""" | |
- time complexity | |
- space complexity | |
- issues / improvements | |
""" | |
if not items: | |
return | |
counter = dict() | |
best = None | |
for item in items: | |
if item in counter: | |
counter[item] += 1 | |
if counter[item] > counter[item]: | |
best = item | |
else: | |
counter[item] = 1 | |
if counter[best] > len(items) // 2: | |
return best |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment