Skip to content

Commit f9c4348

Browse files
authored
Create majorityElementII.py
1 parent 19254a1 commit f9c4348

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Arrays/majorityElementII.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)