public int removeElement(int[] A, int elem) {
// Start typing your Java solution below
// DO NOT write main() function
int length = A.length;
int count = 0;
int i = 0;
while(i < length - count){
if(A[i] == elem){
count++;
for(int j = i; j < length - 1; j++){
A[j] = A[j + 1];
}
continue;
}
i++;
}
return length - count;
}Remove Element
最新推荐文章于 2021-02-04 13:49:30 发布
本文介绍了一种Java实现的数组元素移除算法,通过循环遍历数组并使用计数方式来更新数组长度,实现指定元素的有效移除。
437

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



