题目描述
blablabla
样例
blablabla
算法1
(快速排序) $O()$
blablabla
时间复杂度分析:用了sort()
C++ 代码
class Solution {
public:
int moreThanHalfNum_Solution(vector<int>& nums) {
int n = nums.size();
sort(nums.begin(), nums.end(), greater<int>());
int l = 0, r = n/2;
while (r < n) {
if (nums[l] == nums[r]) return nums[l];
l++;
r++;
}
}
};