删掉一列数中等于elem的所有数,返回新数组的个数
难度:1
看代码吧。。特别容易特别短
class Solution {
public:
int removeElement(int A[], int n, int elem) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
int len=n;
for(int i=n-1;i>=0;i--)
{
if(A[i] == elem)
{
swap(A[len-1],A[i]);
len--;
}
}
return len;
}
};