Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wpjerrykwok/62324c20fcf3bd85f9f7f2163ae44ded to your computer and use it in GitHub Desktop.
Save wpjerrykwok/62324c20fcf3bd85f9f7f2163ae44ded to your computer and use it in GitHub Desktop.
LeetCode - Top Interview 150 - Array - 169. Majority Element
class Solution:
def majorityElement(self, nums: List[int]) -> int:
result = {}
for num in nums:
if num not in result.keys():
result[num] = 1
else:
result[num] += 1
for k in result:
if result[k] > len(nums)/2:
return k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment