您的位置:首页 > 其它

LeetCode之Remove Element

2014-04-14 23:04 204 查看
int removeElement(int A[], int n, int elem) //Remove Element
{
int num=0;
for (int i=0;i<n-num;i++)
{
if (A[i]==elem)
{
while(i!=n-num-1){
if(A[n-num-1]!=elem) {A[i]=A[n-num-1];A[n-num-1]=NULL;break;}
else {A[n-num-1]=NULL;num++;}
}
if(i==n-num-1) A[i]=NULL;
num++;
}
}
return n-num;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode removeElement