229.majority-element-ii
Counter, runtime 96.64%
Published in
1 min readApr 6, 2019
Solution 1: counter
class Solution:
def majorityElement(self, nums: List[int]) -> List[int]:
from collections import Counter
counts = Counter(nums)
threshold = len(nums) / 3
res = []
for key, count in counts.items():
if count > threshold:
res.append(key)
return res# ✔ 66/66 cases passed (44 ms)
# ✔ Your runtime beats 96.64 % of python3 submissions
# ✔ Your memory usage beats 7.61 % of python3 submissions (14.1 MB)