Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
解题思路:
题目大意,删除数组中的指定元素。实现方法比较简单,通过指针,可以在O(n)时间复杂度内解决。
Code:
int removeElement(int A[], int n, int elem) {
int pElem=0;
for(int i=0;i<n;i++)
if(elem!=A[i])
{
A[pElem++]=A[i];
}
return pElem;
}