Skip to content

Commit 78f2994

Browse files
committed
successsuflu
1 parent b359360 commit 78f2994

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

169. Majority Element.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution(object):
2+
def majorityElement(self, nums):
3+
"""
4+
:type nums: List[int]
5+
:rtype: int
6+
"""
7+
nums = sorted(nums)
8+
n = [[nums[0], 1]]
9+
temp = [-1, -1]
10+
for x in nums[1:]:
11+
if x != n[-1][0]:
12+
n.append([x, 1])
13+
else:
14+
n[-1][1] += 1
15+
for x in n:
16+
if x[1] >= temp[1]:
17+
temp = x
18+
return temp[0]

0 commit comments

Comments
 (0)