题目描述
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.
从一个数组中移除所有的指定元素并返回新的长度解题思路
代码
public int removeElement(int[] A, int elem) {
int len = A.length;
for(int i = 0;i < len;){
if(elem==A[i]){
A[i] = A[len-1];
len--;
} else {
i++;
}
}
return len;
}
517




被折叠的 条评论
为什么被折叠?



