Skip to content

Commit 2653087

Browse files
Create majority element.py
1 parent 74485b7 commit 2653087

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

leetcode/array/majority element.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def majorityElement(self, nums: List[int]) -> int:
3+
n=set(nums)
4+
mini=0
5+
ans=0
6+
for i in n:
7+
if(nums.count(i)>mini and nums.count(i)>len(nums)//2):
8+
mini=nums.count(i)
9+
ans=i
10+
return ans

0 commit comments

Comments
 (0)