forked from onlybooks/python-algorithm-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path83-3.py
More file actions
16 lines (12 loc) · 383 Bytes
/
83-3.py
File metadata and controls
16 lines (12 loc) · 383 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import collections
from typing import List
class Solution:
def majorityElement(self, nums: List[int]) -> int:
if not nums:
return None
if len(nums) == 1:
return nums[0]
half = len(nums) // 2
a = self.majorityElement(nums[:half])
b = self.majorityElement(nums[half:])
return [b, a][nums.count(a) > half]