Leetcode:27移除元素
public class 双指针 {
public static void main(String[] args) {
int a[] = {1,2,3,3,4,5};
P pa = new P();
System.out.println("覆盖3后的长度" + pa.two(a));
//与其说删除,不如说是3被4、5覆盖
}
}
class P {
public int two(int a[]) {
int slow = 0,fast;
int target = 3;
;
for(fast = 0; fast < a.length; fast++) {
if(a[fast] != target) {
a[slow++] = a[fast];
}
}
return slow;
}
}