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.
题目描述:
输入一数组,删除其中和输入的元素elem相同的元素并输出修改后的数组大小。
思路:
和上题思路一样。具体可以参考上一题。
http://write.blog.youkuaiyun.com/postedit/40480011
public class Solution {
public int removeElement(int[] A, int elem) {
int index =0;
if(A.length==0)
return 0;
for(int i=0;i<A.length;i++)
{
if(A[i]!=elem)
{
A[index]=A[i];
index++;
}
}
return index;
}
}