[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.

思路:

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

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

 

posted on 2014-12-26 10:56  cha1992  阅读(106)  评论(0编辑  收藏  举报

导航