Remove系列:
two pointers类型
- Remove Duplicates from Sorted Array &II
- Remove Duplicates from Sorted List & II
- Remove Element
- Remove Nth Node From End of List
Remove在array中,一个指针iterate,一个指针保留subarray的最后一个index
public class Solution {
public int removeElement(int[] A, int elem) {
int i = -1;
for (int j = 0; j < A.length; j++) {
if (A[j] != elem) {
A[++i] = A[j];
}
}
return i+1;
}
}

本文介绍了一种名为Remove系列的算法实现方法,主要针对数组中元素的移除操作。通过两个指针来完成对指定元素的删除,一个指针用于遍历整个数组,另一个指针则用来记录子数组的最后一个索引位置。
638

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



