forked from onlybooks/python-algorithm-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path83-2.py
More file actions
13 lines (10 loc) · 339 Bytes
/
83-2.py
File metadata and controls
13 lines (10 loc) · 339 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
import collections
from typing import List
class Solution:
def majorityElement(self, nums: List[int]) -> int:
counts = collections.defaultdict(int)
for num in nums:
if counts[num] == 0:
counts[num] = nums.count(num)
if counts[num] > len(nums) // 2:
return num