Skip to content

Commit 7d7aa03

Browse files
Create 169. Majority Element.py
1 parent ad1d5f5 commit 7d7aa03

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

python/easy/169. Majority Element.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def majorityElement(self, nums: List[int]) -> int:
3+
nums_dict = {}
4+
for number in nums:
5+
nums_dict.setdefault(number,0)
6+
nums_dict[number] += 1
7+
max_number = max(nums_dict, key = lambda x: nums_dict[x])
8+
return max_number

0 commit comments

Comments
 (0)