same as Remove Duplicates from Sorted Array
1 public class Solution { 2 public int removeElement(int[] A, int elem) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(A == null||A.length < 1) 6 return 0; 7 int slowrunner = -1; 8 int fastrunner = 0; 9 while(fastrunner < A.length) 10 { 11 if(A[fastrunner] == elem) 12 { 13 fastrunner++; 14 } 15 else 16 { 17 A[++slowrunner] = A[fastrunner++]; 18 } 19 } 20 return slowrunner+1; 21 } 22 }