Skip to content

Commit 352700a

Browse files
authored
Create 169. Majority Element.py
1 parent 3ab4c0a commit 352700a

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def majorityElement(self, nums: list[int]) -> int:
3+
n = len(nums)
4+
majority = n/2
5+
6+
counter = Counter(nums)
7+
for num, freq in counter.items():
8+
if freq >= majority:
9+
return num
10+
11+
return -1

0 commit comments

Comments
 (0)