Leetcode#169. Majority Element
Problem
Given an array nums of size n, return the majority element.
The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array.
Example 1:
| 1 | Input: nums = [3,2,3] | 
Example 2:
| 1 | Input: nums = [2,2,1,1,1,2,2] | 
Constraints:
- n == nums.length
- 1 <= n <= 5 * 104
- 109 <= nums[i] <= 109
Follow-up:
Could you solve the problem in linear time and in
| 1 | O(1) | 
space?
Solve
解1
| 1 | class Solution: | 
簡化
| 1 | class Solution: | 
特殊解法
| 1 | class Solution: | 
本部落格所有文章除特別聲明外,均採用 CC BY-NC-SA 4.0 許可協議。轉載請註明來自 Imisky!
 評論

