题目
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.
分析
找出数组中的众数(出现次数大于数组长度一半)
代码
|
|
点评
一遍扫描+字典的做法,很容易理解,每次扫描的时候对出现的数 +1,然后判断是否大于 1