题解 | #草原牛群集合#
草原牛群集合
https://www.nowcoder.com/practice/6fc74519ff9c44288dbcec5db7345ded
题目考察的知识点:数组排序
题目解答方法的文字分析:遍历数组,不相等就count++
本题解析所用的编程语言:c++
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param nums int整型vector
* @param val int整型
* @return int整型
*/
int remove_cows(vector<int>& nums, int val)
{
// write code here
int count = 0;
for (int i = 0; i < nums.size(); ++i)
{
if (nums[i] != val)
++count;
}
return count;
}
};
查看9道真题和解析