@@ -0,0 +1,1912 @@
+package main.algorithm.leetcode;%0A%0Aimport org.junit.Test;%0A%0A/**%0A * Title : main.algorithm.leetcode %3Cbr%3E%0A * Description :%0A * %3Cp%3E Runtime: 3 ms, faster than 100.00%25 of Java online submissions for Remove Element.%0A * %3Cp%3E Memory Usage: 37.6 MB, less than 90.60%25 of Java online submissions for Remove Element.%0A * @author chile%0A * @version 1.0%0A * @date 2019/3/19 10:25%0A */%0Apublic class RemoveElement %7B%0A%0A    class Solution %7B%0A        public int removeElement(int%5B%5D nums, int val) %7B%0A%0A            int h = 0, t = nums.length - 1, newLength = 0;%0A%0A            while (true) %7B%0A                while (h %3C= t && nums%5Bh%5D != val) %7B%0A                    newLength++;%0A                    h++;%0A                %7D%0A                while (h %3C t && nums%5Bt%5D == val) %7B%0A                    t--;%0A                %7D%0A                if (h %3E= t) %7B%0A                    break;%0A                %7D else %7B%0A                    nums%5Bh%5D = nums%5Bt%5D;%0A                    h++;%0A                    t--;%0A                    newLength++;%0A                %7D%0A%0A            %7D%0A%0A            return newLength;%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void test1() %7B%0A        int%5B%5D nums = %7B0, 2, 3, 1, 7, 9, 2%7D;%0A        int val = 2;%0A        int leftNums = new Solution().removeElement(nums, val);%0A        assert leftNums == 5;%0A        for (int i = 0; i %3C leftNums; i++) %7B%0A            assert nums%5Bi%5D != val;%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void test2() %7B%0A        int%5B%5D nums = %7B0, 2%7D;%0A        int val = 2;%0A        int leftNums = new Solution().removeElement(nums, val);%0A        assert leftNums == 1;%0A        for (int i = 0; i %3C leftNums; i++) %7B%0A            assert nums%5Bi%5D != val;%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void test3() %7B%0A        int%5B%5D nums = %7B0, 2%7D;%0A        int val = 3;%0A        int leftNums = new Solution().removeElement(nums, val);%0A        assert leftNums == 2;%0A        for (int i = 0; i %3C leftNums; i++) %7B%0A            assert nums%5Bi%5D != val;%0A        %7D%0A    %7D%0A%0A%7D%0A

remove element