LeetCode 169 Majority Element 题解
1.题目:
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/2的数
2.解题思路:
排序取中间
3.代码
1 |
|