【easy】27. Remove Element

时间:2023-04-19 10:48:38

删除等于n的数,并返回剩余元素个数

Given nums = [3,2,2,3], val = 3,

Your function should return length = 2, with the first two elements of nums being 2.
class Solution {
public:
int removeElement(vector<int>& nums, int val) {
int count = ;
int len = nums.size(); for (int i=;i<len;i++){
if (nums[i]!=val){
nums[count++] = nums[i];
}
} return count;
}
};