首页 > 代码库 > [leetcode] Majority Element

[leetcode] Majority Element

Majority Element

Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.

You may assume that the array is non-empty and the majority element always exist in the array.

思路:

最简单的,排序。虽然没超时,但肯定不好。

这里有一种更好的方法,想法很好。

 

[leetcode] Majority Element