Skip to content

Commit a154d8c

Browse files
committed
Time: 148 ms (86.94%), Space: 17.8 MB (95.67%) - LeetHub
1 parent c3e7d29 commit a154d8c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def majorityElement(self, nums: List[int]) -> int:
3+
cnt = 1
4+
curr = nums[0]
5+
for n in nums[1:]:
6+
if curr == n:
7+
cnt += 1
8+
else:
9+
cnt -= 1
10+
if cnt == 0:
11+
cnt = 1
12+
curr = n
13+
return curr
14+
15+

0 commit comments

Comments
 (0)