#include <vector>
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param nums int整型vector
* @return int整型
*/
int majority_cow(vector<int>& nums) {
// write code here
int n = nums.size();
int ve[100000];
int ans;
for (int i = 0; i < n; ++i) {
ve[nums[i]]++;
// cout<<ve[nums[i]]<<endl;
if (ve[nums[i]] > n / 2)
ans = nums[i];
}
return ans;
}
};
一、题目考察的知识点
模拟
二、题目解答方法的文字分析
直接遍历再计数就行
三、本题解析所用的编程语言
c++

京公网安备 11010502036488号