public static int removeElement(int[] A, int elem) {
		if (A == null || A.length == 0)
			return 0;

		int foundNum = 0;
		int i = 0;
		while (i < A.length && i <= A.length - 1 - foundNum) {
			if (A[i] == elem) {
				int j = A.length - 1 - foundNum;
				while (j > i) {
					if (A[j] == elem)
						foundNum++;
					else
						break;
					j--;
				}
				foundNum++;
				A[i] = A[j];
			}
			i++;
		}
		return A.length - foundNum;
	}