There was an error while loading. Please reload this page.
1 parent 19254a1 commit f9c4348Copy full SHA for f9c4348
Arrays/majorityElementII.py
@@ -0,0 +1,16 @@
1
+class Solution(object):
2
+ def majorityElement(self, nums):
3
+ """
4
+ :type nums: List[int]
5
+ :rtype: List[int]
6
+ # make a set(nums) and count the occurence of each element in nums
7
8
+ if len(nums) ==0:
9
+ return []
10
+ result=[]
11
+ oneThird= len(nums)/3
12
+ for elt in set(nums):
13
+ if nums.count(elt) > oneThird:
14
+ result.append(elt)
15
+
16
+ return result
0 commit comments