Given an array and a value, remove all instances of that value in place and return the new length.
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
class Solution {
public:
int removeElement(vector<int>& nums, int val) {
vector<int>a;
for(int i=0;i<nums.size();i++)
{
if(nums[i]!=val)
a.push_back(nums[i]);
}
nums=a;
Remove Element(删除数组某一元素)
最新推荐文章于 2024-01-11 13:00:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)