169. 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.
思路1:hash表
思路2:
此题目是求数组中出现超过一半以上次数的数,所以设置一个element存储当前出现次数最多的数,设置count记录它当前出现的频数,每遇到一个和element不同的数就将count减一。