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.
給一個大小為n的陣列,請找到它的主要元素。主要元素指它出現的次數大於 ⌊ n/2 ⌋ 次的元素。
你可以假設陣列不會是空的,且主要元素總是存在於陣列中。
LeetCode
C++