题目:给定一个数字集合A,要求去除集合A中所有的elem,并返回新集合A的长度
算法:遍历覆盖
public class Solution { public int removeElement(int[] A, int elem) { int length = 0; for (int i=0; i<A.length; ++i) { if (elem != A[i]) { A[length++] = A[i]; } } return length; } }
[LeetCode]Remove Element,布布扣,bubuko.com
原文地址:http://blog.csdn.net/yeweiouyang/article/details/36626661