LeetCode之Remove Element

来源:互联网 发布:inside游戏 知乎 编辑:程序博客网 时间:2024/06/11 18:54
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;}

0 0
原创粉丝点击