Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public class Solution { 2 public int removeElement(int[] A, int elem) { 3 int p1 = 0; 4 int p2 = 0; 5 while(p1<A.length){ 6 if(elem==A[p1]){ 7 p1++; 8 } 9 else{ 10 A[p2] =A[p1]; 11 p2++;p1++; 12 } 13 } 14 return p2; 15 } 16 }