@@ -0,0 +1,1083 @@
+/*%0AGiven an array and a value, remove all instances of that value in place and return the new length.%0A%0ADo not allocate extra space for another array, you must do this in place with constant memory.%0A%0AThe order of elements can be changed. It doesn't matter what you leave beyond the new length.%0A%0AExample:%0AGiven input array nums = %5B3,2,2,3%5D, val = 3%0A%0AYour function should return length = 2, with the first two elements of nums being 2.%0A*/%0A%0Aimport java.util.*;%0A%0Apublic class RemoveElement %7B%0A%09public static int removeElement(int%5B%5D nums, int val) %7B%0A        int j = 0;%0A        for(int i = 0; i %3C nums.length;)%7B%0A            while( i %3C nums.length && nums%5Bi%5D == val) i++;%0A            if(i == nums.length) break;%0A            nums%5Bj++%5D = nums%5Bi++%5D;%0A        %7D%0A        return j;%0A    %7D%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09int%5B%5D nums = new int%5B%5D %7B3,2,2,3%7D;%0A%09%09int val = 3;%0A%09%09for(int i=0; i %3C nums.length; i++)%7B%0A%09%09%09System.out.print(nums%5Bi%5D + %22 %22);%0A%09%09%7D%0A%09%09int res = removeElement(nums, val);%0A%09%09System.out.println();%0A        System.out.println(%22Number of %22 + val + %22: %22 + res);%0A%09%09return;%0A%09%7D%09%0A%7D%0A

remove element