class Solution {
public:
int removeElement(int A[], int n, int elem) {
int i = 0;
int num = 0;
// suppose a general conditions;
// and then apply for the specific cases; test if specific cases meet the code or not; if not ; then change it again;
for(int i = 0;i<n;++i)
{
if(A[i]!=elem)
{
// num point to the last+1 element of new arrary(without element);
A[num]=A[i];
num++;
}
else
{
//i++
}
}
return num;
}
};
remove target element from arrary AC
最新推荐文章于 2021-02-01 12:45:27 发布