remove element

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,查重,Leetcode,two,pointers)