###### 27. Remove Element

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class Solution {
public:
int removeElement(vector<int>& nums, int val) {
if(0==nums.size())
return 0;
sort(nums.begin(),nums.end());
for(int i=0;i<nums.size();)
{
if(nums[i]<val)
i++;
else if(val==nums[i])
nums.erase(nums.begin()+i);
else
break;
}
return nums.size();
}
};
int main()
{
vector<int>number;
int N,x;
cin>>N;
for(int i=0;i<N;i++)
{
cin>>x;
number.push_back(x);
}
int result;
Solution solve;
int target;
cin>>target;
result=solve.removeElement(number,target);
cout<<result<<endl;
for(i=0;i<number.size();i++)
cout<<number[i]<<' ';
return 0;
}

class Solution {
public:
int removeElement(vector<int>& nums, int val) {
int j=0;
for(int i=0;i<nums.size();i++)
{
if(nums[i]!=val)
nums[j++]=nums[i];
}
return j;
}
};

class Solution {
public:
int removeElement(vector<int>& nums, int val) {
for(int i=0;i<nums.size();)
{
if(val==nums[i])
nums.erase(nums.begin()+i);
else
i++;
}
return nums.size();
}
};

#### LeetCode 27 — Remove Element（C++ Java Python）

2014-02-23 15:54:54

#### 27. Remove Element Leetcode Python

2015-01-29 11:53:34

#### LeetCode（27）Remove Element

2015-08-12 16:50:06

#### (Java)LeetCode-27. Remove Element

2016-06-08 15:16:59

#### [leetcode-27]Remove Element(C语言)

2015-07-13 19:12:06

#### LeetCode 27 Remove Element (C,C++,Java,Python)

2015-05-11 20:40:46

#### 【leetcode c++】27 Remove Element

2015-06-22 00:48:04

#### Leetcode #27. Remove Element 移除元素 解题报告

2016-03-29 23:25:15

#### LeetCode 27:Remove Element

2015-06-03 23:05:55

#### LeetCode 27 Remove Element（移除元素）

2015-11-13 23:25:35

## 不良信息举报

27. Remove Element