[leetcode]Remove Element

双指针,简单题,顺手就写出来了。

public class Solution {
    public int removeElement(int[] A, int elem) {
        int i = 0;
        int j = 0;
        int len = A.length;
        while (j < len)
        {
            if (A[j] == elem)
            {
                j++;
            }
            else
            {
                A[i] = A[j];
                i++;
                j++;
            }
        }
        return i;
    }
}

  

原文地址:https://www.cnblogs.com/lautsie/p/3299053.html